#include <bits/stdc++.h>
using namespace std;
struct type {
  double s;
  int id;
} a[300001];
int b[300001];
int ls[100001];
double x[300001];
double y[300001];
struct Type {
  int l, r, s, id;
} q[100001];
int ans[100001];
int c[300001];
int N, Q, n, i, j, k, tot, Ans, S, l, r;
bool cmp(type a, type b) { return a.s < b.s; }
bool Cmp(Type a, Type b) { return a.s < b.s || a.s == b.s && a.r < b.r; }
int gcd(int n, int m) {
  int r = n % m;
  while (!r) {
    n = m;
    m = r;
    r = n % m;
  }
  return m;
}
double xl(int i, int j) {
  if (x[i] == x[j])
    return (y[i] < y[j]) ? 3.14159265358979323846 / 2
                         : 3.14159265358979323846 * 1.5;
  else if (y[i] == y[j])
    return (x[i] < x[j]) ? 0 : 3.14159265358979323846;
  else if (y[i] < y[j]) {
    if (x[i] < x[j])
      return atan((y[j] - y[i]) / (x[j] - x[i]));
    else
      return atan((y[j] - y[i]) / (x[j] - x[i])) + 3.14159265358979323846;
  } else {
    if (x[j] < x[i])
      return atan((y[j] - y[i]) / (x[j] - x[i])) + 3.14159265358979323846;
    else
      return atan((y[j] - y[i]) / (x[j] - x[i])) + 3.14159265358979323846 +
             3.14159265358979323846;
  }
}
int main() {
  scanf("%d", &N);
  for (l = 1; l <= N; l++) {
    ls[l] = tot + 1;
    scanf("%d", &n);
    for (i = 1; i <= n; i++) scanf("%lf%lf", &x[i], &y[i]);
    for (i = 1; i <= n - 1; i++) {
      ++tot;
      a[tot].s = xl(i, i + 1);
      a[tot].id = tot;
    }
    ++tot;
    a[tot].s = xl(n, 1);
    a[tot].id = tot;
  }
  ls[N + 1] = tot + 1;
  S = floor(sqrt(tot));
  sort(a + 1, a + tot + 1, cmp);
  j = 0;
  for (i = 1; i <= tot; i++) {
    if (i == 1 || a[i].s - a[i - 1].s > 0.00000000001) ++j;
    b[a[i].id] = j;
  }
  scanf("%d", &Q);
  for (i = 1; i <= Q; i++) {
    scanf("%d%d", &q[i].l, &q[i].r);
    q[i].l = ls[q[i].l];
    q[i].r = ls[q[i].r + 1] - 1;
    q[i].id = i;
    q[i].s = q[i].l / S;
  }
  sort(q + 1, q + Q + 1, Cmp);
  l = 0;
  r = 0;
  Ans = 0;
  for (i = 1; i <= Q; i++) {
    while (q[i].l < l) {
      --l;
      ++c[b[l]];
      if (c[b[l]] == 1) ++Ans;
    }
    while (r < q[i].r) {
      ++r;
      ++c[b[r]];
      if (c[b[r]] == 1) ++Ans;
    }
    while (l < q[i].l) {
      --c[b[l]];
      if (!c[b[l]]) --Ans;
      ++l;
    }
    while (q[i].r < r) {
      --c[b[r]];
      if (!c[b[r]]) --Ans;
      --r;
    }
    ans[q[i].id] = Ans;
  }
  for (i = 1; i <= Q; i++) printf("%d\n", ans[i]);
}
