#include <bits/stdc++.h>
using namespace std;
int n, q, A[100005 * 3], B[100005 * 3], ans[100005];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
vector<pair<int, int> > G[100005];
vector<int> E[100005];
pair<int, int> SL(pair<int, int> a) {
  int t = gcd(abs(a.first), abs(a.second));
  a.first /= t, a.second /= t;
  return a;
}
int tr[100005];
void upd(int u, int v) {
  for (; u <= n; u += u & -u) tr[u] += v;
}
int qry(int u) {
  int r = 0;
  for (; u; u -= u & -u) r += tr[u];
  return r;
}
map<pair<int, int>, int> mAp;
int main() {
  scanf("%d", &n);
  for (int i = (1), LIM = (n); i <= LIM; i++) {
    int K;
    scanf("%d", &K);
    for (int j = (0), LIM = (K - 1); j <= LIM; j++) {
      scanf("%d%d", &A[j], &B[j]);
      if (j) G[i].push_back(SL(make_pair(A[j] - A[j - 1], B[j] - B[j - 1])));
    }
    G[i].push_back(SL(make_pair(A[0] - A[K - 1], B[0] - B[K - 1])));
  }
  scanf("%d", &q);
  for (int i = (1), LIM = (q); i <= LIM; i++) {
    scanf("%d%d", &A[i], &B[i]);
    E[B[i]].push_back(i);
  }
  for (int i = (1), LIM = (n); i <= LIM; i++) {
    for (auto u : G[i]) {
      int t = mAp[u];
      upd(t + 1, 1), upd(i + 1, -1);
      mAp[u] = i;
    }
    for (int u : E[i]) ans[u] = qry(A[u]);
  }
  for (int i = (1), LIM = (q); i <= LIM; i++) printf("%d\n", ans[i]);
}
