#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const long long int e9 = 1000000000;
const long long int MX = (1 << 18) + 5;
long long int TR[MX];
long long int SZ[MX];
void init(int i, long long int sz) {
  SZ[i] = sz;
  TR[i] = 0;
  if (sz > 1) {
    init(i * 2 + 1, sz / 2);
    init(i * 2 + 2, sz / 2);
  }
}
void upd(int i, long long int l, long long int v) {
  TR[i] += v;
  if (SZ[i] > 1) {
    if (l < SZ[i] / 2) {
      upd(i * 2 + 1, l, v);
    } else {
      upd(i * 2 + 2, l - SZ[i] / 2, v);
    }
  }
}
long long int query(int i, long long int l) {
  if (l <= 0) return 0;
  if (l >= SZ[i]) return TR[i];
  return query(i * 2 + 1, l) + query(i * 2 + 2, l - SZ[i] / 2);
}
int main() {
  ios_base::sync_with_stdio(0);
  long long int N;
  cin >> N;
  vector<vector<unsigned long long int>> A(N);
  for (int i = 0; i < N; i++) {
    int k;
    cin >> k;
    vector<complex<long long int>> p;
    for (int j = 0; j < k; j++) {
      int x, y;
      cin >> x >> y;
      p.emplace_back(x, y);
    }
    for (int j = 0; j < k; j++) {
      complex<long long int> a = p[(j + 1) % k] - p[j];
      long long int x = a.real();
      long long int y = a.imag();
      long long int g = gcd(abs(x), abs(y));
      x /= g;
      y /= g;
      unsigned long long int v =
          (((unsigned long long int)(unsigned)x << 32ull) |
           (unsigned long long int)(unsigned)y);
      A[i].push_back(v);
    }
  }
  int Q;
  cin >> Q;
  vector<int> QL(Q), QR(Q);
  vector<vector<pair<long long int, long long int>>> queries(N + 1);
  for (int i = 0; i < Q; i++) {
    cin >> QL[i] >> QR[i];
    QL[i]--;
    QR[i]--;
    queries[QR[i]].emplace_back(QL[i], i);
  }
  vector<int> ans(Q);
  int cl = 0, cr = 0;
  init(0, 1 << 17);
  unordered_map<unsigned long long int, int> prev;
  for (int i = 0; i < N; i++) {
    for (auto a : A[i]) {
      if (prev.count(a) != 0) {
        upd(0, prev[a], -1);
      }
      prev[a] = i;
      upd(0, i, 1);
    }
    for (auto q : queries[i]) {
      ans[q.second] = query(0, i + 1) - query(0, q.first);
    }
  }
  for (auto &a : ans) {
    cout << a << endl;
  }
}
