var
  t,i,j,n,m,x,min:integer;
    a,b,rez:array [1..1000000] of integer;
begin
  readln(t);
  for i:=1 to t do
  begin
    readln(n,m);
    for j:=1 to n do read(a[i]);
    for j:=1 to m do read(b[i]);
  end;
    x:=abs(a[2]-a[1]);
    min:=abs(b[2]-b[1]);
    for i:=1 to t do
      begin
      for j:=1 to n do if abs(a[i]-a[i+1])<x then x:=abs(a[i]-a[i+1]);
      for j:=1 to m do if abs(b[i]-b[i+1])<min then min:=abs(b[i]-b[i+1]);
      if x=min then rez[i]:=0 else if x<>min then rez[i]:=1;
      writeln(rez[i]);
      end;
  readln();
  readln();
end.