#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int BIT[3 * MAXN], lb[MAXN], rb[MAXN], ans[MAXN];
int get(int i) {
  int res = 0;
  while (i > 0) {
    res += BIT[i];
    i -= i & -i;
  }
  return res;
}
void add(int i, int v) {
  while (i < 3 * MAXN) {
    BIT[i] += v;
    i += i & -i;
  }
}
int gcd(int x, int y) {
  if (x == 0) return y;
  return gcd(y % x, x);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 0; i < (n); i++) {
    lb[i] = v.size();
    int m;
    cin >> m;
    vector<pair<int, int>> p;
    for (int i = 0; i < (m); i++) {
      int a, b;
      cin >> a >> b;
      p.push_back(make_pair(a, b));
    }
    for (int i = 0; i < (m - 1); i++) {
      int a = p[i + 1].first - p[i].first;
      int b = p[i + 1].second - p[i].second;
      int g = abs(gcd(a, b));
      v.push_back(make_pair(a / g, b / g));
    }
    int a = p[0].first - p[m - 1].first;
    int b = p[0].second - p[m - 1].second;
    int g = abs(gcd(a, b));
    v.push_back(make_pair(a / g, b / g));
    rb[i] = v.size();
  }
  int m;
  cin >> m;
  vector<pair<pair<int, int>, int>> q;
  for (int i = 0; i < (m); i++) {
    int a, b;
    cin >> a >> b;
    q.push_back(make_pair(make_pair(b - 1, a - 1), i));
  }
  sort(q.begin(), q.end());
  int rr = 0;
  map<pair<int, int>, int> map;
  for (auto x : q) {
    int l = lb[x.first.second], r = rb[x.first.first], i = x.second;
    while (rr < r) {
      if (map.find(v[rr]) != map.end()) add(map[v[rr]] + 1, -1);
      map[v[rr]] = rr;
      add(rr + 1, 1);
      rr++;
    }
    ans[i] = get(r) - get(l);
  }
  for (int i = 0; i < (m); i++) cout << ans[i] << endl;
  return 0;
}
