using System;
using System.Collections.Generic;
using System.Linq;

namespace _3_zalbe
{
    class Program
    {
        static void Main(string[] args)
        {
            int ppl = Convert.ToInt32(Console.ReadLine());

            int[] final = new int[ppl];

            for (int i = 0; i < ppl; i++)
            {
                final[i] = 1;

                List<Int64> yes = new List<Int64>();
                List<Int64> no = new List<Int64>();

                string[] sh;
                string[] yess;
                string[] nos;

                sh = Console.ReadLine().Split(' ');
                yess = Console.ReadLine().Split(' ');
                nos = Console.ReadLine().Split(' ');

                for (int j = 0; j < Convert.ToInt64(sh[0]); j++)
                {
                    yes.Add(Convert.ToInt64(yess[j]));
                }
                yes.Sort();

                for (int j = 0; j < Convert.ToInt64(sh[1]); j++)
                {
                    no.Add(Convert.ToInt64(nos[j]));
                }
                no.Sort();

                Int64 min = yes[1] - yes[0];
                for (int j = 1; j < yes.Count - 1; j++)
                {
                    min = Math.Min(min, yes[j + 1] - yes[j]);
                }

                List<Int64> all = new List<Int64>();
                all = yes.Concat(no).ToList();
                all.Sort();

                for (int j = 1; j < all.Count; j++)
                {
                    if ((all[j] - all[j - 1] == min) && no.Contains(all[j]))
                    {
                        final[i] = 0;
                        break;
                    }
                }
            }

            for (int i = 0; i < ppl - 1; i++)
            {
                Console.WriteLine(final[i]);
            }
            Console.Write(final[ppl - 1]);
        }
    }
}