#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;
template <typename T>
T abs(T x) {
  return x < 0 ? -x : x;
}
template <typename T>
T sgn(T x) {
  return x < 0 ? -1 : (x > 0 ? 1 : 0);
}
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
int n;
int m;
int o;
map<ii, int> num;
vi v;
int last[300010];
int f[300010];
int x[300010];
int y[300010];
int res[100010];
int tin[100010];
int tout[100010];
vii w[300010];
int get(int x, int y) {
  int d = gcd(abs(x), abs(y));
  x /= d;
  y /= d;
  if (num.count(make_pair(x, y))) return num[make_pair(x, y)];
  num[make_pair(x, y)] = o++;
  return o - 1;
}
int get(int x) {
  x++;
  int y = 0;
  while (x > 0) {
    y += f[x];
    x = (x & (x + 1)) - 1;
  }
  return y;
}
void add(int x, int y) {
  x++;
  while (x <= ((int)(v).size()) + 1) {
    f[x] += y;
    x |= x + 1;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &m);
    for (int i = 0; i < m; i++) scanf("%d%d", &x[i], &y[i]);
    x[m] = x[0];
    y[m] = y[0];
    tin[i] = ((int)(v).size());
    for (int i = 0; i < m; i++)
      v.push_back(get(x[i + 1] - x[i], y[i + 1] - y[i]));
    tout[i] = ((int)(v).size()) - 1;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    w[tin[l]].push_back(make_pair(tout[r], i));
  }
  for (int i = 0; i < o; i++) last[i] = ((int)(v).size());
  memset(f, 0, sizeof(f));
  for (int i = ((int)(v).size()) - 1; i >= 0; i--) {
    add(last[v[i]], -1);
    add(i, 1);
    last[v[i]] = i;
    for (auto& q : w[i]) res[q.second] = get(q.first);
  }
  for (int i = 0; i < m; i++) printf("%d\n", res[i]);
  return 0;
}
