using System;

namespace ConsoleApp1
{
    class Program
    {
        static void razmeni(ref int x, ref int y)
        {
            int p = x;
            x = y;
            y = p;
        }
        static void sort(int[] a, int n)
        {
            int i, j;
            for (i = 0; i < n - 1; i++)
                for (j = i + 1; j < n; j++)
                    if (a[i] > a[j])
                        razmeni(ref a[i], ref a[j]);
        }

        static int nadji(int[] a,int n)
        {
            sort(a, n);
            int i=1, x = a[1] - a[0], br = 1;
            if (n <= 2)
                 return x;
                else
                {
                    while(br<3)
                    {
                        if (x == a[i] - a[i-1])
                            br++;
                        else
                        {
                            x = a[i] - a[i-1];
                            br = 0;
                        }
                    i++;
                    if (i == n)
                    {
                        return 0;
                    }
                }
                }
            return x;
        }
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());
            int br1 = 0, br2 = 0, i, k;
            int[] sum = new int[T];
            string[] x,x1,x2;
            for(i=0;i<T;i++)
            {
                x = Console.ReadLine().Split();
                br1 = (int) Int64.Parse(x[0]);
                br2 = (int) Int64.Parse(x[1]);
               int[] N = new int[br1];
                x1 = Console.ReadLine().Split();
                for (k = 0; k < br1; k++)
                {
                    N[k] = (int) Int64.Parse(x1[k]);
                }
                int[] M = new int[br2];
                x2 = Console.ReadLine().Split();
                for (k = 0; k < br2; k++)
                {
                    M[k] = (int) Int64.Parse(x2[k]);
                }
                if (nadji(N, br1) != nadji(M, br2))
                    sum[i] = 1;
                else
                    sum[i] = 2;
            }
            for (i = 0; i < T; i++)
            {
                Console.WriteLine(sum[i]);
            }
        }
    }
}