#include <bits/stdc++.h>
using namespace std;
template <class T, class T1>
int chkmin(T &x, const T1 &y) {
  return x > y ? x = y, 1 : 0;
}
template <class T, class T1>
int chkmax(T &x, const T1 &y) {
  return x < y ? x = y, 1 : 0;
}
const int MAXN = (1 << 20);
int n, q;
int answer[MAXN];
vector<pair<int, int> > a[MAXN];
vector<pair<int, int> > que[MAXN];
void read() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int len;
    cin >> len;
    for (int j = 0; j < len; j++) {
      int x, y;
      cin >> x >> y;
      a[i].push_back({x, y});
    }
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    que[r].push_back({l, i});
  }
}
int tr[MAXN];
map<pair<int, int>, int> last;
void add(int i, int v) {
  while (i <= n) {
    tr[i] += v;
    i += (i & -i);
  }
}
int query(int i) {
  int ret = 0;
  while (i) {
    ret += tr[i];
    i -= (i & -i);
  }
  return ret;
}
int ask(int l, int r) { return query(r) - query(l - 1); }
int gcd(int x, int y) {
  if (x < 0) x *= -1;
  if (y < 0) y *= -1;
  while (y > 0) {
    int tmp = x % y;
    x = y;
    y = tmp;
  }
  return x;
}
void solve() {
  for (int i = 1; i <= n; i++) {
    int x = a[i].back().first, y = a[i].back().second;
    for (int j = 0; j < ((int)a[i].size()); j++) {
      pair<int, int> nw = {a[i][j].first - x, a[i][j].second - y};
      int G = gcd(nw.first, nw.second);
      nw.first /= G;
      nw.second /= G;
      x = a[i][j].first;
      y = a[i][j].second;
      a[i][j] = nw;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (auto it : a[i]) {
      if (last.count(it)) add(last[it], -1);
      add(i, 1);
      last[it] = i;
    }
    for (auto it : que[i]) answer[it.second] = ask(it.first, i);
  }
  for (int i = 0; i < q; i++) cout << answer[i] << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
