#include <bits/stdc++.h>
using namespace std;
struct stree {
  vector<vector<int> > t;
  vector<int> a;
  stree(){};
  stree(vector<int> a) : a(a) {
    t.resize(4 * a.size());
    build(1, 0, a.size() - 1);
  }
  void build(int v, int tl, int tr) {
    if (tl == tr)
      t[v].push_back(a[tl]);
    else {
      int tm = (tl + tr) / 2;
      build(v + v, tl, tm);
      build(v + v + 1, tm + 1, tr);
      merge(t[v + v].begin(), t[v + v].end(), t[v + v + 1].begin(),
            t[v + v + 1].end(), back_inserter(t[v]));
    }
  }
  long long num(int v, int tl, int tr, int l, int r, long long x) {
    if (l > r || l > tr) return 0;
    if (tl == l && tr == r)
      return t[v].end() - upper_bound(t[v].begin(), t[v].end(), x);
    else {
      int tm = (tl + tr) / 2;
      return num(v + v, tl, tm, l, min(r, tm), x) +
             num(v + v + 1, tm + 1, tr, max(l, tm + 1), r, x);
    }
  }
};
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
struct pt {
  long long x, y;
  pt(){};
  pt(long long x, long long y) : x(x), y(y){};
  void nor() {
    long long d = gcd(abs(x), abs(y));
    x /= d;
    y /= d;
  }
};
pt operator-(pt a, pt b) { return pt(a.x - b.x, a.y - b.y); }
bool operator<(pt a, pt b) { return make_pair(a.x, a.y) < make_pair(b.x, b.y); }
int n, k, q, l, r;
vector<pt> v;
vector<int> fr, to, ne;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  fr = to = vector<int>(n);
  for (int i = 0; i < n; ++i) {
    fr[i] = v.size();
    cin >> k;
    vector<pt> p(k);
    for (int j = 0; j < k; ++j) cin >> p[j].x >> p[j].y;
    p.push_back(p[0]);
    for (int j = 0; j < k; ++j) {
      p[j] = p[j] - p[j + 1];
      p[j].nor();
      v.push_back(p[j]);
    }
    to[i] = v.size() - 1;
  }
  n = v.size();
  ne.assign(n, n);
  map<pt, int> ma;
  for (int i = n - 1; i >= 0; --i) {
    if (ma.count(v[i])) ne[i] = ma[v[i]];
    ma[v[i]] = i;
  }
  stree t(ne);
  cin >> q;
  while (q--) {
    cin >> l >> r;
    --l;
    --r;
    l = fr[l];
    r = to[r];
    cout << t.num(1, 0, t.a.size() - 1, l, r, r) << "\n";
  }
  return 0;
}
