#include <bits/stdc++.h>
using namespace std;
int s[200000], s1[200000], s2[200000], d[524288], f[200000];
int l(int q) {
  int w = 1, r = 0, t;
  for (t = 131072; t; t >>= 1) {
    w <<= 1;
    if (q > t) {
      q -= t;
      r += d[w];
      w++;
    }
  }
  return r;
}
void m(int w, int e) {
  for (w += 262144; w; w >>= 1) d[w] += e;
}
int k(int q) {
  if (f[f[q]] != f[q]) f[q] = k(f[q]);
  return f[q];
}
void qs(int q, int w) {
  int e = q, r = w, t = s[q + (rand() % (w - q + 1))], y;
  do {
    while (s[e] < t) e++;
    while (s[r] > t) r--;
    if (e <= r) {
      y = s[e];
      s[e] = s[r];
      s[r] = y;
      y = s1[e];
      s1[e] = s1[r];
      s1[r] = y;
      y = s2[e];
      s2[e] = s2[r];
      s2[r] = y;
      e++;
      r--;
    }
  } while (e <= r);
  if (q < r) qs(q, r);
  if (e < w) qs(e, w);
}
int main() {
  int q, w, e, r, t, *a = new int[200000], *a1 = new int[200000], g[200000];
  for (w = 0; w < 524288; w++) d[w] = 0;
  cin >> q;
  for (w = 0; w < q; w++) {
    scanf("%d%d", &a[w], &a1[w]);
    a1[w] += a[w];
  }
  cin >> t;
  for (w = 0; w < t; w++) {
    scanf("%d%d", &s[w], &s1[w]);
    s[w]--;
    s2[w] = w;
  }
  qs(0, t - 1);
  r = t - 1;
  for (w = q - 1; w >= 0; w--) {
    f[w] = w;
    e = w;
    while ((e < q - 1) && (a1[w] >= a[e + 1])) {
      m(e, -d[262144 + e]);
      f[e] = k(e + 1);
      e = f[e];
    }
    if ((w == e) && (w < q - 1)) m(w, a[w + 1] - a1[w]);
    if ((e < q - 1) && (a1[w] > a1[e])) {
      m(e, a1[e] - a1[w]);
      a1[e] = a1[w];
    }
    for (; (r >= 0) && (s[r] == w); r--) g[s2[r]] = l(s1[r]);
  }
  for (w = 0; w < t; w++) printf("%d\n", g[w]);
  return 0;
}
