#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXPOL = 100000;
const int MAXQ = 100000;
const int MAXPTOT = 300000;
struct P {
  int x, y;
  P() {}
  P(int x, int y) : x(x), y(y) {}
};
P operator-(const P &a, const P &b) { return P(a.x - b.x, a.y - b.y); }
struct Q {
  int l, r, id;
};
bool operator<(const Q &a, const Q &b) { return a.l > b.l; }
int npol;
vector<P> pol[MAXPOL];
int nq;
Q q[MAXQ];
int qans[MAXQ];
map<pair<int, int>, int> mp;
int lst[MAXPTOT], nlst;
int off[MAXPOL + 1];
pair<int, int> o[MAXPTOT];
int nxt[MAXPTOT];
int bit[MAXPTOT + 1];
void bmod(int idx, int by) {
  ++idx;
  while (idx <= nlst) {
    bit[idx] += by;
    idx += idx & -idx;
  }
}
int bget(int idx) {
  ++idx;
  int ret = 0;
  while (idx > 0) {
    ret += bit[idx];
    idx -= idx & -idx;
  }
  return ret;
}
void solve() {
  nlst = 0;
  off[0] = 0;
  mp.clear();
  for (int i = (0); i < (npol); ++i) {
    for (int j = (0); j < (((int)(pol[i]).size())); ++j) {
      P a = pol[i][j], b = pol[i][(j + 1) % ((int)(pol[i]).size())];
      P d = b - a;
      int g = gcd(abs(d.x), abs(d.y));
      d.x /= g, d.y /= g;
      pair<int, int> key = make_pair(d.x, d.y);
      int id;
      if (!mp.count(key)) {
        id = ((int)(mp).size());
        mp[key] = id;
      } else
        id = mp[key];
      lst[nlst++] = id;
    }
    off[i + 1] = nlst;
  }
  for (int i = (0); i < (nlst); ++i) o[i] = make_pair(lst[i], i);
  sort(o, o + nlst);
  for (int i = (0); i < (nlst); ++i)
    nxt[o[i].second] =
        i + 1 < nlst && o[i + 1].first == o[i].first ? o[i + 1].second : -1;
  sort(q, q + nq);
  int at = nlst;
  for (int i = (0); i <= (nlst); ++i) bit[i] = 0;
  for (int i = (0); i < (nq); ++i) {
    int to = off[q[i].l];
    while (at > to) {
      --at;
      bmod(at, +1);
      if (nxt[at] != -1) bmod(nxt[at], -1);
    }
    qans[q[i].id] = bget(off[q[i].r + 1] - 1);
  }
}
void run() {
  scanf("%d", &npol);
  for (int i = (0); i < (npol); ++i) {
    int cnt;
    scanf("%d", &cnt);
    pol[i] = vector<P>(cnt);
    for (int j = (0); j < (((int)(pol[i]).size())); ++j)
      scanf("%d%d", &pol[i][j].x, &pol[i][j].y);
  }
  scanf("%d", &nq);
  for (int i = (0); i < (nq); ++i)
    scanf("%d%d", &q[i].l, &q[i].r), --q[i].l, --q[i].r, q[i].id = i;
  solve();
  for (int i = (0); i < (nq); ++i) printf("%d\n", qans[i]);
}
int main() {
  run();
  return 0;
}
