using System;

namespace tk1z3
{
    class Program
    {
        static void Main(string[] args)
        {
            //long[] pera1;
            string[] unos1, unos2, unos3;
            int t = 0;
            int[] zastavica = new int[75001];
            long min=Int64.MaxValue;
            int br_takmicara=Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < br_takmicara; i++)
            {
                unos1 = Console.ReadLine().Split();
                unos2 = Console.ReadLine().Split();
                long[] pera1=Array.ConvertAll(unos2, long.Parse);
                Array.Sort(pera1);
                for (int j = 0; j < Convert.ToInt64(unos1[0]) - 1; j++)
                {
                    min = Math.Min((Convert.ToInt64(pera1[j + 1]) - Convert.ToInt64(pera1[j])), min);
                    
                }
                unos3 = Console.ReadLine().Split();
                long[] pera2 = Array.ConvertAll(unos3, long.Parse);
                Array.Sort(pera2);

                for (int k = 0; k < Convert.ToInt64(unos1[1]); k++)
                {
                    while ((Convert.ToInt64(pera1[0]) + t * min) <= Convert.ToInt64(pera2[k]))
                    {
                        
                        if (Convert.ToInt64(pera2[k]) == Convert.ToInt64(pera1[0]) + t * min)
                        {
                            zastavica[i] = 1;
                            break;
                        }
                        t++;
                        //Console.WriteLine(min);
                    }
                    
                }
            }
            for(int i=0;i<br_takmicara;i++)
            {
                Console.WriteLine(1-zastavica[i]);
            }
        }
    }
}