#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
int tree[N];
int MaxIdx = 0;
void update(int idx, int val) {
  while (idx <= MaxIdx) {
    tree[idx] += val;
    idx += (idx & -idx);
  }
}
int read(int idx) {
  int sum = 0;
  while (idx > 0) {
    sum += tree[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
vector<pair<int, int>> g[N];
map<pair<int, int>, int> pre;
vector<int> result;
int x[N], y[N];
vector<pair<int, int>> a(1);
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
pair<int, int> reduce(int a, int b) {
  auto k = gcd(abs(a), abs(b));
  return {a / k, b / k};
}
int L[N], R[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) cin >> x[i] >> y[i];
    L[i] = a.size();
    for (int i = 0; i < k; i++) {
      a.push_back(reduce(x[i] - x[(i + 1) % k], y[i] - y[(i + 1) % k]));
    }
    R[i] = a.size() - 1;
  }
  int q;
  cin >> q;
  result.assign(q, -1);
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    g[R[b - 1]].push_back({L[a - 1], i});
  }
  MaxIdx = a.size() - 1;
  for (int i = 1; i <= MaxIdx; i++) {
    if (pre[a[i]]) update(pre[a[i]], -1);
    update(i, 1);
    pre[a[i]] = i;
    for (auto k : g[i]) {
      int ans = read(i) - read(k.first - 1);
      result[k.second] = ans;
    }
  }
  for (auto k : result) {
    cout << k << "\n";
  }
}
