#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<long long, long long>& a,
         const pair<long long, long long>& b) {
  double x = atan2((double)(a.second), (double)(a.first));
  double y = atan2((double)(b.second), (double)(b.first));
  if (abs(x - y) < 1e-12) return false;
  return x < y;
}
bool cmp_eq(const pair<long long, long long>& a,
            const pair<long long, long long>& b) {
  return (cmp(a, b) == false && cmp(b, a) == false);
}
int n;
vector<pair<long long, long long> > ply[100005], vec[100005];
vector<pair<long long, long long> > za;
int beg[100005], en[100005], prer = -1;
vector<int> val;
vector<int> pre;
map<int, int> M;
int q;
vector<pair<long long, long long> > query[300005];
vector<int> add[300005];
int ans[100005];
struct seg {
  int seg[(1 << 20)];
  void update(int p, int a) {
    p += (1 << 19) - 1;
    seg[p] += a;
    while (p) {
      p = (p - 1) / 2;
      seg[p] = seg[p * 2 + 1] + seg[p * 2 + 2];
    }
  }
  int query(int a, int b, int k, int l, int r) {
    if (r < a || b < l) return 0;
    if (a <= l && r <= b) return seg[k];
    return query(a, b, k * 2 + 1, l, (l + r) / 2) +
           query(a, b, k * 2 + 2, (l + r) / 2 + 1, r);
  }
} kaede;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    for (int j = 0; j < x; j++) {
      int a, b;
      scanf("%d%d", &a, &b);
      ply[i].push_back(make_pair(a, b));
    }
    for (int j = 0; j < x; j++) {
      pair<long long, long long> p =
          make_pair(ply[i][(j + 1) % x].first - ply[i][j].first,
                    ply[i][(j + 1) % x].second - ply[i][j].second);
      vec[i].push_back(p);
      za.push_back(p);
    }
  }
  sort(za.begin(), za.end(), cmp);
  za.erase(unique(za.begin(), za.end(), cmp_eq), za.end());
  for (int i = 0; i < n; i++) {
    beg[i] = prer + 1;
    en[i] = prer + vec[i].size();
    prer += vec[i].size();
    for (int j = 0; j < vec[i].size(); j++) {
      int d = lower_bound(za.begin(), za.end(), vec[i][j], cmp) - za.begin();
      assert(d < za.size() && cmp_eq(za[d], vec[i][j]));
      val.push_back(d);
    }
  }
  for (int i = 0; i < val.size(); i++) {
    int V = val[i];
    if (M.find(V) == M.end()) {
      pre.push_back(-1);
      kaede.update(i, 1);
    } else {
      pre.push_back(M[V]);
      add[M[V]].push_back(i);
    }
    M[V] = i;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    x = beg[x];
    y = en[y];
    query[x].push_back(make_pair(y, i));
  }
  for (int i = 0; i < 300005; i++) {
    for (int j = 0; j < query[i].size(); j++) {
      pair<long long, long long> rng = make_pair(i, query[i][j].first);
      int id = query[i][j].second;
      ans[id] = kaede.query(rng.first, rng.second, 0, 0, (1 << 19) - 1);
    }
    for (int j = 0; j < add[i].size(); j++) {
      kaede.update(add[i][j], 1);
    }
  }
  for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
}
