#include <bits/stdc++.h>
using namespace std;
inline int getint() {
  int num = 0, flag = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  while (c >= '0' && c <= '9') num = num * 10 + c - 48, c = getchar();
  return num * flag;
}
int n, m;
int cnt;
map<pair<int, int>, int> M;
struct node {
  int x, y;
} P[600005];
vector<int> G[600005];
int lst[600005], t[600005];
struct qr {
  int l, r, id;
} Q[600005];
int ans[600005];
inline bool cmp(qr x, qr y) { return x.r < y.r; }
inline void update(int x, int num) {
  for (int i = x; i <= n; i += i & (-i)) t[i] += num;
}
inline int getans(int x) {
  int num = 0;
  for (int i = x; i; i -= i & (-i)) num += t[i];
  return num;
}
inline int gcd(int p, int q) { return q ? gcd(q, p % q) : p; }
int main() {
  n = getint();
  for (int i = 1; i <= n; i++) {
    int K = getint();
    for (int j = 1; j <= K; j++) P[j].x = getint(), P[j].y = getint();
    P[K + 1] = P[1];
    for (int j = 1; j <= K; j++) {
      pair<int, int> p(P[j + 1].x - P[j].x, P[j + 1].y - P[j].y);
      int g = gcd(abs(p.first), abs(p.second));
      p.first /= g, p.second /= g;
      if (!M[p]) M[p] = ++cnt;
      G[i].push_back(M[p]);
    }
  }
  m = getint();
  for (int i = 1; i <= m; i++)
    Q[i].l = getint(), Q[i].r = getint(), Q[i].id = i;
  sort(Q + 1, Q + m + 1, cmp);
  int now = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      if (lst[G[i][j]]) update(lst[G[i][j]], -1);
      lst[G[i][j]] = i;
      update(lst[G[i][j]], 1);
    }
    while (now <= m && Q[now].r == i)
      ans[Q[now].id] = getans(Q[now].r) - getans(Q[now].l - 1), now++;
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}
