#include <bits/stdc++.h>
using namespace std;
const int maxn = int(3e5) + 100;
struct Point {
  int x, y;
  bool operator<(const Point &b) const {
    if (x != b.x) return x < b.x;
    return y < b.y;
  }
  bool operator==(const Point &b) const { return (x == b.x && y == b.y); }
  Point operator-(const Point &b) const { return Point{x - b.x, y - b.y}; }
};
int sq;
int n, m, mm, casesum;
int a[maxn], ans[maxn], idx[maxn], cnt[maxn];
pair<int, int> range[maxn];
Point p[maxn], que[maxn], b[maxn];
int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x % y)); }
void read() {
  scanf("%d", &n);
  m = 0;
  for (int i = 1; i <= n; ++i) {
    int s;
    scanf("%d", &s);
    range[i] = make_pair(m + 1, m + s);
    for (int j = 1; j <= s; ++j) scanf("%d%d", &p[m + j].x, &p[m + j].y);
    Point tmp = p[m + 1];
    for (int j = 2; j <= s; ++j) p[m + j - 1] = p[m + j] - p[m + j - 1];
    p[m + s] = tmp - p[m + s];
    for (int j = 1; j <= s; ++j) {
      int d = gcd(abs(p[m + j].x), abs(p[m + j].y));
      p[m + j].x /= d;
      p[m + j].y /= d;
    }
    m += s;
  }
  scanf("%d", &casesum);
  for (int i = 1; i <= casesum; ++i) {
    scanf("%d%d", &que[i].x, &que[i].y);
    que[i].x = range[que[i].x].first;
    que[i].y = range[que[i].y].second;
  }
}
bool cmp(int x, int y) {
  if (que[x].x / sq != que[y].x / sq) return que[x].x / sq < que[y].x / sq;
  return que[x].y < que[y].y;
}
void solve() {
  for (int i = 1; i <= m; ++i) b[i] = p[i];
  sort(b + 1, b + 1 + m);
  mm = unique(b + 1, b + 1 + m) - b - 1;
  for (int i = 1; i <= m; ++i) a[i] = lower_bound(b + 1, b + 1 + mm, p[i]) - b;
  for (int i = 1; i <= casesum; ++i) idx[i] = i;
  sq = sqrt(m) + 1;
  sort(idx + 1, idx + 1 + casesum, cmp);
  for (int i = 1, j = 2, k = 1, s = 0; i <= casesum; ++i) {
    int cur = idx[i];
    while (k < que[cur].y)
      if ((++cnt[a[++k]]) == 1) ++s;
    while (j > que[cur].x)
      if ((++cnt[a[--j]]) == 1) ++s;
    while (k > que[cur].y)
      if ((--cnt[a[k--]]) == 0) --s;
    while (j < que[cur].x)
      if ((--cnt[a[j++]]) == 0) --s;
    ans[cur] = s;
  }
  for (int i = 1; i <= casesum; ++i) printf("%d\n", ans[i]);
}
int main() {
  read();
  solve();
  return 0;
}
