#include <bits/stdc++.h>
using namespace std;
inline int gcd(int x, int y) {
  if (x < 0) x = -x;
  if (y < 0) y = -y;
  if (x > y) swap(x, y);
  while (x) y %= x, swap(x, y);
  return y;
}
map<pair<int, int>, int> mp;
int a[300005], cnt, now, qwq = -1000000001, l[100005], r[100005];
int lst[300005], ans[100005], tree[300005];
pair<pair<int, int>, int> b[100005];
inline int lowbit(int x) { return x & (-x); }
inline int ask(int x) {
  if (!x) return x;
  return tree[x] + ask(x ^ lowbit(x));
}
inline void add(int x, int y) {
  if (x > 300000 || !x) return;
  tree[x] += y, add(x + lowbit(x), y);
}
int main(int argc, char** argv) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int m, X, Y, lx, ly;
    scanf("%d%d%d", &m, &X, &Y);
    lx = X, ly = Y;
    l[i] = cnt + 1;
    for (int j = 2; j <= m; j++) {
      int XX, YY;
      scanf("%d%d", &XX, &YY);
      int x = XX - lx, y = YY - ly;
      int G = gcd(x, y);
      if (G) x /= G, y /= G;
      if (!x && y)
        if (y > 0)
          y = 1;
        else
          y = -1;
      if (!y && x)
        if (x > 0)
          x = 1;
        else
          x = -1;
      int t = mp[{x, y}];
      if (!t) t = mp[{x, y}] = ++now;
      a[++cnt] = t;
      lx = XX, ly = YY;
    }
    int XX = X, YY = Y;
    int x = XX - lx, y = YY - ly;
    int G = gcd(x, y);
    if (G) x /= G, y /= G;
    if (!x && y)
      if (y > 0)
        y = 1;
      else
        y = -1;
    if (!y && x)
      if (x > 0)
        x = 1;
      else
        x = -1;
    int t = mp[{x, y}];
    if (!t) t = mp[{x, y}] = ++now;
    a[++cnt] = t;
    lx = XX, ly = YY;
    r[i] = cnt;
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &b[i].first.second, &b[i].first.first);
    b[i].first.second = l[b[i].first.second];
    b[i].first.first = r[b[i].first.first];
    b[i].second = i;
  }
  sort(b + 1, b + q + 1);
  int now = 1;
  for (int i = 1; i <= q; i++) {
    while (now <= b[i].first.first)
      add(lst[a[now]], -1), lst[a[now]] = now, add(now++, 1);
    ans[b[i].second] = ask(b[i].first.first) - ask(b[i].first.second - 1);
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
  return 0;
}
