#include <bits/stdc++.h>
using namespace std;
struct Tree {
  vector<long long> tree;
  int shift;
  explicit Tree(int n = 1) {
    shift = 1;
    while (shift < n) shift *= 2;
    tree.assign(2 * shift, 0);
  }
  void set(int pos, long long x) {
    pos += shift;
    tree[pos] = x;
    for (pos /= 2; pos; pos /= 2) tree[pos] = tree[pos * 2] + tree[pos * 2 + 1];
  }
  long long findSum(int l, int r) {
    l += shift;
    r += shift;
    long long ans = 0;
    while (l <= r) {
      if (l & 1) ans += tree[l++];
      if (!(r & 1)) ans += tree[r--];
      l /= 2;
      r /= 2;
    }
    return ans;
  }
};
struct Query {
  int l, r, num;
  Query() {}
  Query(int l, int r, int num) : l(l), r(r), num(num) {}
};
bool operator<(Query q1, Query q2) { return q1.r < q2.r; }
void out() {
  cout.flush();
  int n;
  cin >> n;
  exit(0);
}
int ggcd(int x, int y) {
  x = abs(x);
  y = abs(y);
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}
map<pair<int, int>, int> MAP;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> vs;
  vector<int> st;
  for (int i = 0; i < n; ++i) {
    st.push_back(vs.size());
    int k;
    cin >> k;
    vector<pair<int, int> > ps(k + 1);
    for (int i = 0; i < k; ++i) cin >> ps[i].first >> ps[i].second;
    ps[k] = ps[0];
    for (int j = 1; j <= k; ++j) {
      int x = ps[j].first - ps[j - 1].first;
      int y = ps[j].second - ps[j - 1].second;
      int g = ggcd(x, y);
      x /= g;
      y /= g;
      if (!MAP.count(make_pair(x, y))) {
        int sz = MAP.size();
        MAP[make_pair(x, y)] = sz;
      }
      vs.push_back(MAP[make_pair(x, y)]);
    }
  }
  st.push_back(vs.size());
  vector<int> pr(vs.size(), -1), poss(vs.size(), -1);
  for (int i = 0; i < (int)vs.size(); ++i) {
    pr[i] = poss[vs[i]];
    poss[vs[i]] = i;
  }
  vector<Query> qs;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    qs.push_back(Query(l - 1, r - 1, i));
  }
  sort(qs.begin(), qs.end());
  vector<int> anss(q, -1);
  Tree tree(vs.size());
  int curr = 0;
  for (int i = 0; i < q; ++i) {
    while (curr < st[qs[i].r + 1]) {
      tree.set(curr, 1);
      if (pr[curr] >= 0) tree.set(pr[curr], 0);
      curr++;
    }
    anss[qs[i].num] = tree.findSum(st[qs[i].l], st[qs[i].r + 1] - 1);
  }
  for (int i = 0; i < q; ++i) cout << anss[i] << "\n";
  out();
  return 0;
}
