#include <bits/stdc++.h>
using namespace std;
double ep = 1e-10;
bool lte(double x, double y) { return x < y || fabs(x - y) <= ep; }
struct circle {
  int x, r, idx;
  bool operator<(const circle& a) const { return this->r < a.r; }
  bool has(int x, int y) {
    double xd = this->x - x;
    double yd = y;
    double dist = sqrt(xd * xd + yd * yd);
    return lte(dist, r);
  }
};
vector<circle> pc[100005];
int n, m, t[100005], r[100006], x[200005], y[200005], ans[200005];
circle c[200005];
int main() {
  scanf("%d", &n);
  memset(ans, -1, sizeof(ans));
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &c[i].x, &c[i].r, &c[i].idx);
    c[i].idx = i;
    for (int j = c[i].x - c[i].r; j <= c[i].x + c[i].r; j++) {
      pc[j + 30000].push_back(c[i]);
    }
  }
  int cnt = 0;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    int idx = x[i] + 30000;
    for (int j = 0; j < pc[idx].size(); j++) {
      if (ans[pc[idx][j].idx] == -1 && pc[idx][j].has(x[i], y[i])) {
        cnt++;
        ans[pc[idx][j].idx] = i + 1;
      }
    }
  }
  printf("%d\n", cnt);
  for (int i = 0; i < n; i++) {
    printf("%d%c", ans[i], n - 1 == i ? '\n' : ' ');
  }
  return 0;
}
