#include<iostream>
using namespace std;

int Partition (int arr[], int s, int e){
	int pivot = arr[e];
	int pIndex = s;
	
	for (int i = s; i < e; i++){
		if (arr[i] < pivot) {
			int temp = arr[i];
			arr[i] = arr[pIndex];
			arr[pIndex] = temp;
			pIndex++;
		}
	}
	
	int temp = arr[e];
	arr[e] = arr[pIndex];
	arr[pIndex] = temp;
	
	return pIndex;
}

void QuickSort (int arr[], int s, int e) {
	if (s < e) {
		int p = Partition (arr, s, e);
		QuickSort (arr, s, (p-1));
		QuickSort (arr, (p+1), e);
	}
}

int main(){
	int t,n,m;
	cin >> t;
	int a[n],b[m],x[t];
	for (int i = 0; i < t; i++){
		cin >> n >> m;
		for (int j = 0; j < n; j++){
			cin >> a[j];
			}
		for (int j = 0; j < m; j++){
			cin >> b[j];
		}
		QuickSort (a, 0, n-1);
		if (n < 3 or (n > 2 and (a[n-1]-a[n-3] % a[n-1]-a[n-2] == 0 or a[n-1]-a[n-3] % a[n-1]-a[n-2] == (a[n-1]-a[n-3])/2))){
			x[i] = 1;
		}
		else {
			x[i] = 0;
		}
	}
	for (int i = 0; i < n; i++){
		cout << x[i] << endl;
	}	
}