using System;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = Convert.ToInt32(Console.ReadLine());
            string[] kraj = new string[t];
            while (t>0)
            {
                String[] elementi = Console.ReadLine().Split();
                int n = Convert.ToInt32(elementi[0]);
                int m = Convert.ToInt32(elementi[1]);
                String[] prihvaceni = Console.ReadLine().Split();
                String[] neprihvaceni = Console.ReadLine().Split();
                int x = 0;
                int k = 0;
                int r = 0;
                for (int i = 0; i < n; i++)
                {
                    int a = 0;
                    if (i + 1 < prihvaceni.Length)
                    {
                        a = Convert.ToInt32(prihvaceni[i + 1]);
                    }
                    int b = 0;
                    if (i+2<prihvaceni.Length)
                    {
                        b = Convert.ToInt32(prihvaceni[i + 2]);
                    }
                    int c = Convert.ToInt32(prihvaceni[i]);
                    if (Math.Max(a,b)-Math.Min(a,b)==Math.Max(a,c)-Math.Min(a,c))
                    {
                        x = 1;
                        k = Math.Max(a, b) - Math.Min(a, b);
                    }
                    else if (Math.Max(a, b) - Math.Min(a, b) == 2*(Math.Max(a, c) - Math.Min(a, c)))
                    {
                        x = 1;
                        k = Math.Max(a, c) - Math.Min(a, c);
                    }
                    else if (2*(Math.Max(a, c) - Math.Min(a, c)) == Math.Max(a, c) - Math.Min(a, c))
                    {
                        x = 1;
                        k = Math.Max(a, c) - Math.Min(a, c);
                    }
                    else
                    {
                        x = 0;
                    }
                    for (int j = 0; j < m; j++)
                    {
                        int d = Convert.ToInt32(neprihvaceni[j]);
                        if (d==c)
                        {
                            x = 0;
                        }
                        else if (d==c+k||d==c-k)
                        {
                            x = 0;
                        }

                    }
                    
                    kraj[r] = x.ToString();
                    r++;
                    t--;
                }
                Console.WriteLine(kraj);

            }
        }
    }
}