#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
} a[300050];
vector<pair<int, int> > v[300050];
struct node2 {
  int l, r, id;
  friend bool operator<(const node2 &a, const node2 &b) { return a.r < b.r; }
} q[300050];
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int ans[300050];
int n, m;
map<pair<int, int>, int> h;
int tot, las[300050];
int ct[300050];
inline void add(int x, int num) {
  while (x <= n) ct[x] += num, x += x & -x;
}
inline int ask(int x, int ret = 0) {
  while (x) ret += ct[x], x -= x & -x;
  return ret;
}
int main() {
  cin >> n;
  for (int i = 1, k; i <= n; ++i) {
    scanf("%d", &k);
    v[i].resize(k);
    for (int j = 1; j <= k; ++j) scanf("%d%d", &a[j].x, &a[j].y);
    a[0] = a[k];
    for (int j = 0; j < k; ++j) {
      v[i][j] = make_pair(a[j + 1].y - a[j].y, a[j + 1].x - a[j].x);
      int gc = gcd(abs(v[i][j].first), abs(v[i][j].second));
      if (gc) v[i][j].first /= gc, v[i][j].second /= gc;
      if (!h[v[i][j]]) h[v[i][j]] = ++tot;
    }
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
  sort(q + 1, q + m + 1);
  for (int i = 1, j = 1; i <= n; ++i) {
    for (pair<int, int> k : v[i]) {
      int t = h[k];
      if (las[t] == i) continue;
      if (las[t]) add(las[t], -1);
      las[t] = i;
      add(i, 1);
    }
    while (j <= m && q[j].r == i) {
      ans[q[j].id] = ask(q[j].r) - ask(q[j].l - 1);
      ++j;
    }
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}
