Problem: One of the questions children often ask is "How many stars are there in the sky?" Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the northern hemisphere. With a decent telescope, you may find many more, but, as the sight field will be limited, you may find much less at a time.

Children may ask the same questions to their parents on a planet of some solar system billions of light-years away from the Earth. Their telescopes are similar to ours with circular sight fields, but alien kids have many eyes and can look into different directions at a time through many telescopes.

Given a set of positions of stars, a set of telescopes and the directions they are looking to, your task is to count up how many stars can be seen through these telescopes.



Input

The input consists of one or more datasets. The number of datasets is less than 50. Each dataset describes stars and the parameters of the telescopes used.

The first line of a dataset contains a positive integer n not exceeding 500, meaning the number of stars. Each of the n lines following it contains three decimal fractions, sx, sy, and sz. They give the position (sx, sy, sz) of the star described in Euclidean coordinates. You may assume -1000 ≤ sx ≤ 1000, -1000 ≤ sy ≤ 1000, -1000 ≤ sz ≤ 1000 and (sx, sy, sz) ≠ (0, 0, 0).

Then comes a line containing a positive integer m not exceeding 50, meaning the number of telescopes. Each of the following m lines contains four decimal fractions, tx, ty, tz, and φ, describing a telescope.

The first three numbers represent the direction of the telescope. All the telescopes are at the origin of the coordinate system (0, 0, 0) (we ignore the size of the planet). The three numbers give the point (tx, ty, tz) which can be seen in the center of the sight through the telescope. You may assume -1000 ≤ tx ≤ 1000, -1000 ≤ ty ≤ 1000, -1000 ≤ tz ≤ 1000 and (tx, ty, tz) ≠ (0, 0, 0).

The fourth number φ (0 ≤ φ ≤ π/2) gives the angular radius, in radians, of the sight field of the telescope.

Let us defie that θi,j is the angle between the direction of the i-th star and the center direction of the j-th telescope and φjis the angular radius of the sight field of the j-th telescope. The i-th star is observable through the j-th telescope if and only if θi,j is less than . You may assume that |θi,j - φj| > 0.00000001 for all pairs of i and j.

<image>


Figure 1: Direction and angular radius of a telescope

The end of the input is indicated with a line containing a single zero.

Output

For each dataset, one line containing an integer meaning the number of stars observable through the telescopes should be output. No other characters should be contained in the output. Note that stars that can be seen through more than one telescope should not be counted twice or more.

Example

Input

3
100 0 500
-500.243 -200.1 -300.5
0 300 200
2
1 1 1 0.65
-1 0 0 1.57
3
1 0 0
0 1 0
0 0 1
4
1 -1 -1 0.9553
-1 1 -1 0.9554
-1 -1 1 0.9553
-1 1 -1 0.9554
3
1 0 0
0 1 0
0 0 1
4
1 -1 -1 0.9553
-1 1 -1 0.9553
-1 -1 1 0.9553
-1 1 -1 0.9553
0


Output

2
1
0

Solution (in CPP):

Solution:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
using namespace std;
 
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
 
#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

const double EPS = 1e-8;
 
typedef long long ll;
typedef pair<int, int> pii;

int n;
vector<double> sx, sy, sz;
int m;

set<int> ans;

#define POW(x) ((x)*(x))

void rotate(double &x, double &y, double theta)
{
	double sx, sy;
	const double C = cos(theta), S = sin(theta);
	sx = C * x - S * y;
	sy = S * x + C * y;

	x = sx;
	y = sy;
}

bool in_circle(double cx, double cy, double cz, double r, double x, double y, double z)
{
	double dist = (POW(x-cx)+POW(y-cy)+POW(z-cz));
	return dist <= POW(r);
}

void cnt()
{
	double tx, ty, tz, phi;
	cin >> tx >> ty >> tz >> phi;

	const double theta = atan2(tz, tx);
	rotate(tx, tz, -theta);

	const double theta2 = atan2(ty, tx);
	rotate(tx, ty, -theta2);

	const double height = tx * tan(phi);

	rep(i, n) {
		double x, y, z;
		x = sx[i]; y = sy[i]; z = sz[i];
		rotate(x, z, -theta);
		rotate(x, y, -theta2);

		if (x * tx < 0) continue;
		//if (abs(x) > abs(tx)) continue;

		double yp = (tx / x) * y;
		double zp = (tx / x) * z;
		if (in_circle(tx, 0, 0, height, tx, yp, zp))
			ans.insert(i);
	}
}

int main()
{
	while (cin >> n, n) {
		sx = vector<double>(n);
		sy = vector<double>(n);
		sz = vector<double>(n);
		rep(i, n)
			cin >> sx[i] >> sy[i] >> sz[i];

		cin >> m;
		ans.clear();
		rep(i, m)
			cnt();
		cout << ans.size() << endl;
	}
	return 0;
}