#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cmath>

using namespace std;

void swap(int *xp, int *yp)  
{  
    int temp = *xp;  
    *xp = *yp;  
    *yp = temp;  
}

void bubbleSort(int arr[], int n)  
{  
    int i, j;  
    for (i = 0; i < n-1; i++)      
    for (j = 0; j < n-i-1; j++)  
        if (arr[j] > arr[j+1])  
            swap(&arr[j], &arr[j+1]);  
}  

void printArray(int arr[], int size)  
{  
    int i;  
    for (i = 0; i < size; i++)  
        cout << arr[i] << " ";  
    cout << endl;  
}

int main() {
    int t;
    int n;
    int m;
    int i;
    int j;
    int k;
    int l;
    int p;
    int temp;
    int a[100];
    int b[100];
    int c[100];
    int Re[100];
    int x;
    int g;
    int br;
    int min;
    
    cin >> t;
    cin >> n;
    cin >> m;
    for (br = 1; br <= t; br++) {
        Re[br]=1;
        for (i = 1; i <= n; i++) {
            cin >> a[i];
            c[i] = a[i];
        }
        for (j = 1; j <= m; j++) {
            cin >> b[j];
            c[n + j] = b[j];
        }
        
        bubbleSort(c,m+n);
   
        x = c[2]-c[1];
        for (g=3;g<=m+n;g++){
            if (c[g]-c[g-1]==x){}
            else { Re[br]=0;}
        }
    }
    printArray(Re,t);
    return 0;
}