#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef ll niz[100005];

int n, q;
niz a, b, u, v, x, y, r, z;

ll det(ll ax, ll ay, ll bx, ll by, ll cx, ll cy) {
	return ax*by + bx*cy + cx*ay - ay*bx - by*cx - cy*ax;
}

ll kv(ll x) {
	return x*x;
}

ll dist2(ll a, ll b, ll c, ll d) {
	return kv(a-c) + kv(b-d);
}

bool presek(ll u, ll v, ll x, ll y, ll a, ll b, ll r) {
	ld dc = abs(det(u, v, x, y, a, b)) / sqrt((ld)dist2(u, v, x, y));
	/*
	ld eps = 1.2e-12;
	ld err = abs((dc / r) - 1);
	if (err < eps) {
		cerr << "Upozorenje! Vrednosti su previse blizu! Resenje je nepouzdano!\n";
		exit(1);
	}
	*/
	return dc < r;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	cin >> n;
	for (int i=0; i<n; i++)
		cin >> x[i] >> y[i] >> u[i] >> v[i];
	cin >> q;
	for (int j=0; j<q; j++)
		cin >> a[j] >> b[j] >> r[j];

	for (int i=0; i<n; i++) {
		int lo = 0, hi = q-1, o = q;
		while (lo <= hi) {
			int mid = (lo + hi) >> 1;
			if (presek(u[i], v[i], x[i], y[i], a[mid], b[mid], r[mid])) {
				o = mid;
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		z[o]++;
	}
	cerr << '\n';

	ll sol = 0;

	for (int i=0; i<q; i++)
		cout << (sol += z[i]) << '\n';
}