uses
  Math;
  
const
  maxn = 100000;
  maxm = 100000;
  maxatt = 1000000;
  attempts : longint = 100000000;

var
  maxtry, cnt, x, y, n, m, i, l, r, c, j : longint;
  a, b : array[1..maxn] of longint;
  ca, cb : array[1..maxn] of longint;
  ansl, ansr, ansx, ansy : array[1..maxm] 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;
  ca[1] := 1;
  cb[1] := 1;
  for i := 2 to n do begin
    if ca[i] <> ca[i - 1] then begin
      ca[i] := ca[i - 1] + 1;
    end else begin
      ca[i] := ca[i];
    end; 
    if cb[i] <> cb[i - 1] then begin
      cb[i] := cb[i - 1] + 1;
    end else begin
      cb[i] := cb[i - 1];
    end;
  end;
  fillchar(ansl, sizeof(ansl), 0);
  fillchar(ansr, sizeof(ansl), 0);
  fillchar(ansx, sizeof(ansl), 0);
  fillchar(ansy, sizeof(ansl), 0);
  read(m);
  c := 1;
  for i := 1 to m do begin
    read(l, r);
    found := false;
    for j := 1 to c - 1 do begin
      if (ansl[j] >= l) and (r >= ansr[j]) then begin
        if (ansx[j] = -1) then begin 
          writeln('0 0');
        end else begin
          writeln(ansx[j], ' ', ansy[j]);
        end;
        found := true;
        break;
      end;
    end;
    if (found) then continue;
    cnt := 0;
    found := false;
    ansl[c] := l;
    ansr[c] := r;
    c := c + 1;
    if (ca[l] = ca[r]) or (cb[l] = cb[r]) then begin
      writeln(-1);
      continue;
    end;
    maxtry := min(attempts div (m - i + 1), maxatt);
    while (cnt < maxtry) do begin
      x := random(r - l + 1) + l;
      y := random(r - l + 1) + l;
      if check(x, y) then begin
        writeln(x, ' ', y);
        ansx[c - 1] := x;
        ansy[c - 1] := y;
        found := true;
        break;
      end;
      cnt := cnt + 1;
      attempts := attempts - 1;
    end;
    if not found then begin
      writeln('0 0');
      ansx[c - 1] := -1;
    end;  
  end;
end.
