program cojs620;
var
x,y,x1,y1,i:longint;
c1,c2:longint;
n:longint;
ans:longint;
begin
assign(input,'carpet.in');
assign(output,'carpet.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
readln;
readln(c1,c2);
reset(input);
readln(n);
ans:=-1;
for i:=1 to n do
begin
readln(x,y,x1,y1);
if (c1>=x)and(c2>=y)and(c1<=x+x1)and(c2<=y+y1)then
ans:=(i);
end;
writeln(ans);
close(input);
close(output);
end.