#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int maxm = 300010;
const double eps = 1e-7;
inline int rd() {
  int ret = 0, f = 1;
  char gc = getchar();
  while (gc < '0' || gc > '9') {
    if (gc == '-') f = -f;
    gc = getchar();
  }
  while (gc >= '0' && gc <= '9') ret = ret * 10 + gc - '0', gc = getchar();
  return ret * f;
}
int n, m, Q;
int pos[maxn], bel[maxm], org[maxm], s[maxn], lst[maxm];
int ans[maxn];
struct point {
  double x, y, z;
  point() {}
  point(double a, double b) { x = a, y = b, z = atan2(y, x); }
  point operator+(const point &a) { return point(x + a.x, y + a.y); }
  point operator-(const point &a) { return point(x - a.x, y - a.y); }
  double operator*(const point &a) { return x * a.y - y * a.x; }
  point operator*(const double &a) { return point(x * a, y * a); }
} pp[maxm], pl[maxm];
struct node {
  int x, y, org;
  node() {}
} q[maxn];
bool cmp1(const int &a, const int &b) {
  if (fabs(pl[a].z - pl[b].z) < eps) return a < b;
  return pl[a].z < pl[b].z;
}
bool cmp2(const node &a, const node &b) { return a.y < b.y; }
void updata(int x, int v) {
  if (!x) return;
  for (int i = x; i <= n; i += i & -i) s[i] += v;
}
int query(int x) {
  int i, ret = 0;
  for (i = x; i; i -= i & -i) ret += s[i];
  return ret;
}
int main() {
  n = rd();
  int i, j;
  for (i = 1; i <= n; i++) {
    m += rd();
    pos[i] = m;
    for (j = pos[i - 1] + 1; j <= pos[i]; j++) {
      pp[j].x = rd(), pp[j].y = rd();
      if (j != pos[i - 1] + 1) pl[j - 1] = pp[j] - pp[j - 1];
      bel[j] = i;
    }
    pl[m] = pp[pos[i - 1] + 1] - pp[m];
  }
  for (i = 1; i <= m; i++) org[i] = i;
  sort(org + 1, org + m + 1, cmp1);
  for (i = 1; i <= m; i++) {
    if (i != 1 && fabs(pl[org[i]] * pl[org[i - 1]]) < eps)
      lst[org[i]] = org[i - 1];
  }
  Q = rd();
  for (i = 1; i <= Q; i++) {
    q[i].x = rd(), q[i].y = rd(), q[i].org = i;
  }
  sort(q + 1, q + Q + 1, cmp2);
  for (i = j = 1; i <= Q; i++) {
    for (; j <= pos[q[i].y]; j++) {
      updata(bel[j], 1);
      updata(bel[lst[j]], -1);
    }
    ans[q[i].org] = query(q[i].y) - query(q[i].x - 1);
  }
  for (i = 1; i <= Q; i++) printf("%d\n", ans[i]);
  return 0;
}
