#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <stack>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n,m;
		cin >> n >> m;
		long long a[n];
		long long b[m];
		for(int i = 0; i < n; ++i)cin >> a[i];
		for(int i = 0; i < m; ++i)cin >> b[i];
		
		for(int i = 0; i < n; ++i)
		{
			int pos = 0;
			int temp = abs(a[i]-b[pos]);
			for(int j = 0; j < n; ++j)
			{
				for(int k = 0; k < n; ++k)
				{
					if(a[j] + temp == a[k])
					{
						cout << "0";
						goto label;
					}
				}
			}
		}
		cout << "1";
		label:
			continue;
	}
}