rt,wssb
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL phi = 1e7+14;
LL a[phi],b[phi];
int main()
{
ios::sync_with_stdio(0);
LL t;
cin>>t;
while(t--)
{
LL sum = 0,n,m;
cin>>n>>m;
for(LL i=1;i<=n;i++) cin>>a[i];
for(LL i=1;i<=m;i++) cin>>b[i];
LL f=1,be=1;
for(LL i=1;i<=n;i++)
{
while(b[f]<a[i] && f<=m) f++;
while(b[be]<=a[i] && be<=m) be++;
sum ^= (be-f);
}
cout<<sum<<"\n";
}
return 0;
}