#include <iostream>
using namespace std;

void swap(int* a, int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

int part (int arr[], int low, int high)
{
    int pivot = arr[high];    // pivot
    int i = (low - 1);

    for (int j = low; j <= high- 1; j++)
    {
        //if current element is smaller than pivot, increment the low element
        //swap elements at i and j
        if (arr[j] <= pivot)
        {
            i++;    // increment index of smaller element
            swap(&arr[i], &arr[j]);
        }
    }
    swap(&arr[i + 1], &arr[high]);
    return (i + 1);
}

//quicksort algorithm
void quickSort(int arr[], int low, int high)
{
    if (low < high)
    {
        //partition the array
        int pivot = part(arr, low, high);

        //sort the sub arrays independently
        quickSort(arr, low, pivot - 1);
        quickSort(arr, pivot + 1, high);
    }
}

int main()
{
    int t;
    cin>>t;
    int tt[t];
    for(int i=0;i<t;i++)
    {
    int p=1;
    int n,m;
    cin>>n>>m;
    int a[n];
    int b[m];
    int x;
    for(int j=0;j<n;j++)
    {
        cin>>x;
        a[j]=x;
    }
    for(int j=0;j<m;j++)
    {
        cin>>x;
        b[j]=x;
    }
    quickSort(a,0,n-1);
    x=a[1]-a[0];
    for(int j=1;j<n-1;j++)
    {
        if(a[j+1]-a[j]!=x)
        {
            p=0;
            break;
        }
    }
    tt[i]=p;
    }
    for(int i=0;i<t;i++)
    {
        cout<<t<<"\n";
    }
    return 0;
}