#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
pair<int, int> a[maxn];
map<pair<int, int>, int> pre;
vector<int> qry[maxn];
int n, cnt, ql[maxn], qr[maxn], L[maxn], R[maxn], x[maxn], y[maxn], ans[maxn],
    C[maxn];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
pair<int, int> cal(int x, int y) {
  int g = gcd(abs(x), abs(y));
  return pair<int, int>(x / g, y / g);
}
void add(int x, int v) {
  for (int i = x; i <= cnt; i += i & -i) C[i] += v;
}
int query(int x) {
  int ret = 0;
  for (int i = x; i; i -= i & -i) ret += C[i];
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, k; i <= n; ++i) {
    scanf("%d", &k);
    for (int j = 0; j < k; ++j) scanf("%d%d", &x[j], &y[j]);
    L[i] = cnt + 1;
    for (int j = 0; j < k; ++j)
      a[++cnt] = cal(x[(j + 1) % k] - x[j], y[(j + 1) % k] - y[j]);
    R[i] = cnt;
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d", &ql[i], &qr[i]);
    ql[i] = L[ql[i]];
    qr[i] = R[qr[i]];
    qry[qr[i]].push_back(i);
  }
  for (int i = 1; i <= cnt; ++i) {
    if (pre[a[i]]) add(pre[a[i]], -1);
    pre[a[i]] = i;
    add(i, 1);
    for (int j : qry[i]) ans[j] = query(qr[j]) - query(ql[j] - 1);
  }
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
  return 0;
}
