#include <bits/stdc++.h>
;
using namespace std;
using Xxxxxxxxx = char;
using Xxxxxxxxxxx = int;
using Xxx = long long;
using XxxxXxxxxx = long double;
Xxx xXXxXXxXXXXxXXXXX();
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  xXXxXXxXXXXxXXXXX();
  return 0;
}
Xxx xXXXXXXxxXXxx(Xxx x, Xxx xx) {
  if (x < 0) x = -x;
  if (xx < 0) xx = -xx;
  for (; xx; x ^= xx ^= x ^= xx) x %= xx;
  return x;
}
Xxx xx;
vector<pair<Xxx, Xxx>> xxx[100001];
Xxx xxxx[100000];
Xxx xxXXXXxxXXxxXxx(Xxx xxxx) {
  Xxx xx;
  cin >> xx;
  for (; xx--;) {
    Xxx xxxxx, xxxxxx;
    cin >> xxxxx >> xxxxxx;
    xxx[xxxx].emplace_back(xxxxx, xxxxxx);
  }
  return 0;
}
struct {
  Xxx xx[100001];
  Xxx xxxxxx(Xxx x, Xxx xxx) {
    for (; x <= 100000; x += x & -x) {
      xx[x] += xxx;
    }
    return 0;
  }
  Xxx xxxxx(Xxx x) {
    Xxx xxx = 0;
    for (; x; x -= x & -x) {
      xxx += xx[x];
    }
    return xxx;
  }
} xxXxxxxXxx;
map<pair<Xxx, Xxx>, Xxx> xxxxxx;
Xxx xxXXxXxXxx(Xxx xXxx) {
  Xxx x;
  for (x = 0; x < xxx[xXxx].size(); ++x) {
    Xxx xx = (x + 1) % xxx[xXxx].size();
    Xxx xxxx = xxx[xXxx][x].first - xxx[xXxx][xx].first;
    Xxx xxxxx = xxx[xXxx][x].second - xxx[xXxx][xx].second;
    Xxx xxxxxxx = xXXXXXXxxXXxx(xxxx, xxxxx);
    xxxx /= xxxxxxx;
    xxxxx /= xxxxxxx;
    pair<Xxx, Xxx> x(xxxx, xxxxx);
    if (xxxxxx[x] != 0) {
      xxXxxxxXxx.xxxxxx(xxxxxx[x], -1);
      xxXxxxxXxx.xxxxxx(xxxxxx[x] = xXxx, 1);
    } else {
      xxXxxxxXxx.xxxxxx(xxxxxx[x] = xXxx, 1);
    }
  }
  return 0;
}
Xxx xxXxXXxXXxXXX[100000];
Xxx xXXxXXxXXXXxXXXXX() {
  cin >> xx;
  for (Xxx x = 1; x <= xx; ++x) {
    xxXXXXxxXXxxXxx(x);
  }
  xxXXXXxxXXxxXxx(0);
  for (Xxx x = 0; x < xxx[0].size(); ++x) {
    xxxx[x] = x;
  }
  sort(xxxx, xxxx + xxx[0].size(),
       [&](Xxx x, Xxx xx) { return xxx[0][x] < xxx[0][xx]; });
  for (Xxx xXXxxXX = xxx[0].size(); xXXxxXX--;) {
    Xxx x = xxxx[xXXxxXX];
    Xxx xxxx = xxx[0][x].first;
    Xxx xxxxx = xxx[0][x].second;
    for (; xx >= xxxx; --xx) {
      xxXXxXxXxx(xx);
    }
    xxXxXXxXXxXXX[x] = xxXxxxxXxx.xxxxx(xxxxx);
  }
  for (Xxx x = 0; x < xxx[0].size(); ++x) {
    cout << xxXxXXxXXxXXX[x] << (Xxxxxxxxx)10;
  }
  return 0;
}
