#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const long long INF = 0x3f3f3f3f3f3f3f3f;
inline long long readll() {
  long long x(0), op(1);
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') op = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * op;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const int sz = 100009;
struct P {
  long long x, y;
  P(long long x, long long y) : x(x), y(y) {}
  P operator-(P p) { return P(x - p.x, y - p.y); }
  P simp() {
    long long d = abs(gcd(x, y));
    return P(x / d, y / d);
  }
  bool operator<(const P &q) const {
    return make_pair(x, y) < make_pair(q.x, q.y);
  }
};
int L[sz], R[sz];
vector<P> ps;
struct Q {
  int l, r, id;
  bool operator<(const Q &q) const { return r < q.r; }
} q[sz];
int ans[sz];
struct BIT {
  static const int BIT_SZ = 1e6 + 9;
  long long bit[BIT_SZ + 1];
  long long p[BIT_SZ + 1];
  int n;
  void init(int nn) {
    for (int i = 0; i < nn + 5; ++i) bit[i] = p[i] = 0;
    n = nn;
  }
  void add(int i, long long x) {
    while (i <= n) bit[i] += x, i += ((i) & (-i));
    p[i] += x;
  }
  void set(int i, long long x) {
    add(i, x - p[i]);
    p[i] = x;
  }
  long long get(int i) { return p[i]; }
  long long sum(int i) {
    if (i <= 0) return 0;
    long long s = 0;
    while (i) s += bit[i], i -= ((i) & (-i));
    return s;
  }
  long long query(int l, int r) {
    if (l >= r) return 0;
    return sum(r - 1) - sum(l - 1);
  }
} bit;
map<P, int> mpre;
int main() {
  int n = readll();
  ps.push_back(P(INF, INF));
  for (int i = 0; i < n; ++i) {
    vector<P> v;
    int cnt = readll();
    for (int i = 0; i < cnt; ++i) {
      long long x = readll(), y = readll();
      v.push_back({x, y});
    }
    L[i] = ((int)(ps.size()));
    for (int i = 0; i < cnt; ++i) {
      ps.push_back((v[(i + 1) % cnt] - v[i]).simp());
    }
    R[i] = ((int)(ps.size()));
  }
  int m = readll();
  for (int i = 0; i < m; ++i) {
    q[i].l = L[readll() - 1], q[i].r = R[readll() - 1];
    q[i].id = i;
  }
  sort(q, q + m);
  int curr = 1;
  bit.init(((int)(ps.size())) + 5);
  for (int i = 0; i < m; ++i) {
    while (curr < q[i].r) {
      if (mpre[ps[curr]]) bit.add(mpre[ps[curr]], -1);
      bit.add(curr, 1);
      mpre[ps[curr]] = curr;
      curr++;
    }
    ans[q[i].id] = bit.query(q[i].l, q[i].r);
  }
  for (int i = 0; i < m; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
