const
  maxn = 100000;
  attempts : longint = 10000000;
  maxatt = 1000000;

var
  cnt, x, y, n, m, i, l, r : longint;
  a, b : array[1..maxn] of longint;
  found : boolean;

function check(i, j : longint) : boolean;
begin
  check := false;
  if (i <> j) and (a[i] <> a[j]) and (b[i] <> b[j]) then
    check := true;
end;

begin
  assign(input, 'mosaic.in');
  assign(output, 'mosaic.out');
  reset(input);
  rewrite(output);
  read(n);
  for i := 1 to n do begin
    read(a[i], b[i]);
  end;
  read(m);
  for i := 1 to m do begin
    read(l, r);
    cnt := 0;
    found := false;
    while (cnt < attempts div (m - i + 1)) and (cnt <= maxatt) do begin
      x := random(r - l + 1) + l;
      y := random(r - l + 1) + l;
      if check(x, y) then begin
        writeln(x, ' ', y);
        found := true;
        break;
      end;
      cnt := cnt + 1;
      attempts := attempts - 1;
    end;
    if not found then
      writeln('0 0');
  end;
end.
