const
  maxn = 100000;

var
  n, m, i, l, r : longint;
  a, b, nexta, nextb : array[1..maxn] of longint;

function check(i, j : integer) : 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;
  nexta[n] := n + 1;
  for i := n - 1 downto 1 do begin
    if (a[i] = a[i + 1]) then
      nexta[i] := nexta[i + 1]
    else
      nexta[i] := i + 1;  
  end;
  nextb[n] := n + 1;
  for i := n - 1 downto 1 do begin
    if (b[i] = b[i + 1]) then
      nextb[i] := nextb[i + 1]
    else
      nextb[i] := i + 1;  
  end;
  read(m);
  for i := 1 to m do begin
    read(l, r);
    if (nexta[l] <= r) and check(l, nexta[l]) then begin
      writeln(l, ' ', nexta[l]);
    end else if (nextb[l] <= r) and check(l, nextb[l]) then begin
      writeln(l, ' ', nextb[l]);
    end else if (nexta[l] <= r) and (nextb[l] <= r) and check(nexta[l], nextb[l]) then begin
      writeln(nexta[l], ' ', nextb[l]);
    end else begin
      writeln('0 0');
    end;  
  end;
end.
