#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<long long, long long>, int> > iranyok;
vector<pair<pair<int, int>, int> > query;
int ans[100009];
int n;
int test;
int darab[300009];
vector<int> irtip[100009];
int kezdet[100009];
vector<int> tipus;
pair<long long, long long> kul(pair<long long, long long> x,
                               pair<long long, long long> y) {
  return {(long long)(x.first - y.first), (long long)(x.second - y.second)};
}
long long cross(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first * b.second - a.second * b.first;
}
bool compIrany(pair<pair<long long, long long>, int> a,
               pair<pair<long long, long long>, int> b) {
  long long cr = cross(a.first, b.first);
  bool fenta = true;
  if (a.first.second < 0 || (a.first.second == 0 && a.first.first < 0))
    fenta = false;
  bool fentb = true;
  if (b.first.second < 0 || (b.first.second == 0 && b.first.first < 0))
    fentb = false;
  if (fenta == fentb) {
    return cr > 0;
  }
  return fenta;
}
bool mas(pair<long long, long long> x, pair<long long, long long> y) {
  if (x.second * y.second < 0) return true;
  if (x.second == 0 && y.second == 0) {
    if (x.first * y.first < 0) return true;
  }
  return cross(x, y) != 0;
}
int SQ;
bool hasonlit(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {
  int xblokk = x.first.first / SQ;
  int yblokk = y.first.first / SQ;
  if (xblokk < yblokk) return true;
  if (xblokk == yblokk) {
    return x.first.second < y.first.second;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int csucsok;
    cin >> csucsok;
    vector<pair<long long, long long> > pgon(csucsok);
    for (int j = 0; j < csucsok; j++) {
      cin >> pgon[j].first >> pgon[j].second;
    }
    for (int j = 0; j < csucsok; j++) {
      iranyok.push_back({kul(pgon[(j + 1) % csucsok], pgon[j]), i});
    }
  }
  sort(iranyok.begin(), iranyok.end(), compIrany);
  int tipuscnt = 1;
  irtip[iranyok[0].second].push_back(1);
  for (int i = 1; i < iranyok.size(); i++) {
    if (mas(iranyok[i - 1].first, iranyok[i].first)) {
      tipuscnt++;
    }
    irtip[iranyok[i].second].push_back(tipuscnt);
  }
  for (int i = 1; i <= n; i++) {
    kezdet[i] = tipus.size();
    for (int j = 0; j < irtip[i].size(); j++) {
      tipus.push_back(irtip[i][j]);
    }
  }
  kezdet[n + 1] = tipus.size();
  cin >> test;
  for (int qq = 1; qq <= test; qq++) {
    int LL, RR;
    cin >> LL >> RR;
    query.push_back({{kezdet[LL], kezdet[RR + 1] - 1}, qq});
  }
  SQ = sqrt(kezdet[n + 1]);
  sort(query.begin(), query.end(), hasonlit);
  int kezdopont = 0;
  int vegpont = -1;
  int cans = 0;
  for (int u = 0; u < query.size(); u++) {
    pair<int, int> qu = query[u].first;
    if (u == 0 || qu.first / SQ != query[u - 1].first.first / SQ) {
      for (int j = 0; j <= kezdet[n + 1]; j++) darab[j] = 0;
      kezdopont = qu.first;
      vegpont = kezdopont - 1;
      cans = 0;
    }
    while (vegpont < qu.second) {
      vegpont++;
      darab[tipus[vegpont]]++;
      if (darab[tipus[vegpont]] == 1) cans++;
    }
    while (kezdopont < qu.first) {
      darab[tipus[kezdopont]]--;
      if (darab[tipus[kezdopont]] == 0) cans--;
      kezdopont++;
    }
    while (kezdopont > qu.first) {
      kezdopont--;
      darab[tipus[kezdopont]]++;
      if (darab[tipus[kezdopont]] == 1) cans++;
    }
    ans[query[u].second] = cans;
  }
  for (int i = 1; i <= test; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
