#include <bits/stdc++.h>
using std::make_pair;
using std::map;
using std::pair;
using std::vector;
map<pair<int, int>, int> m;
const int N = 300005;
int t[N], cnt, b[N], k, n, x[N], y[N], Q, l, r, Ans[N], lst[N], tot = 2;
struct query {
  int l, id;
};
vector<query> q[N];
struct note {
  int l, r;
} a[N];
int gcd(int x, int y) {
  if (x % y == 0) return abs(y);
  return gcd(y, x % y);
}
int getid(int x, int y) {
  if (y == 0) {
    if (x > 0)
      return 1;
    else
      return 0;
  }
  int g = gcd(x, y);
  x /= g, y /= g;
  if (!m[make_pair(x, y)]) m[make_pair(x, y)] = ++tot;
  return m[make_pair(x, y)];
}
int lowbit(int x) { return x & (-x); }
void upd(int x, int y) {
  if (x == 0) return;
  while (x <= cnt) {
    t[x] += y;
    x += lowbit(x);
  }
}
int getsum(int x) {
  if (x == 0) return 0;
  int ret = 0;
  while (x) {
    ret += t[x];
    x -= lowbit(x);
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    a[i].l = cnt + 1;
    for (int j = 0; j < k; j++) scanf("%d%d", &x[j], &y[j]);
    for (int j = 0; j < k; j++)
      b[++cnt] = getid(x[j] - x[(j + 1) % k], y[j] - y[(j + 1) % k]);
    a[i].r = cnt;
  }
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d", &l, &r);
    q[a[r].r].push_back({a[l].l, i});
  }
  for (int i = 1; i <= cnt; i++) {
    if (lst[b[i]]) upd(lst[b[i]], -1);
    lst[b[i]] = i;
    upd(i, 1);
    int sum = getsum(i);
    for (auto j : q[i]) Ans[j.id] = sum - getsum(j.l - 1);
  }
  for (int i = 1; i <= Q; i++) printf("%d\n", Ans[i]);
}
