#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
long long B[N];
void U(long long i, long long x) {
  ++i;
  while (i < N) B[i] += x, i += i & -i;
}
long long Q(long long i) {
  ++i;
  long long r = 0;
  while (i) r += B[i], i -= i & -i;
  return r;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct pp {
  int x, y;
  pp(int a = 0, int b = 0) : x(a), y(b) {}
};
bool operator<(const pp &A, const pp &B) {
  return A.x == B.x ? A.y < B.y : A.x < B.x;
}
map<pp, int> M;
int X[N], Y[N], ans[N];
vector<int> V[N];
vector<long long> qu[N];
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q, p = 0;
  cin >> n;
  for (int i = 1, m; i <= n; ++i) {
    cin >> m;
    for (int j = 0; j < m; ++j) cin >> X[j] >> Y[j];
    X[m] = X[0];
    Y[m] = Y[0];
    for (int j = 1; j <= m; ++j) {
      long long x = X[j] - X[j - 1], y = Y[j] - Y[j - 1];
      long long g = gcd(abs(x), abs(y));
      x /= g;
      y /= g;
      pp t(x, y);
      if (!M[t]) M[t] = ++p;
      V[i].push_back(M[t]);
    }
  }
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    long long a, b;
    cin >> a >> b;
    qu[a].push_back(b << 32 | i);
  }
  map<int, int> lst;
  for (int i = n; i >= 1; --i) {
    for (auto &it : V[i]) {
      if (lst[it]) U(lst[it], -1);
      lst[it] = i;
      U(i, 1);
    }
    for (auto &it : qu[i]) ans[it & ~0U] = Q(it >> 32);
  }
  for (int i = 1; i <= q; ++i) cout << ans[i] << endl;
}
