#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* 3次元幾何 */

typedef double P_type;
typedef double G_real; //実数の戻り値(float or double or long double)
const G_real P_eps = 1e-8; //整数の時はゼロ

struct P3{
  P_type x, y, z;
  P3(P_type x = 0, P_type y = 0, P_type z = 0): x(x), y(y), z(z) {}

  P3 operator-() const {
    return P3(-x, -y, -z);
  }

  P3 operator+(const P3 &B) const {
    return P3(x + B.x, y + B.y, z + B.z);
  }

  P3 operator-(const P3 &B) const {
    return P3(x - B.x, y - B.y, z - B.z);
  }

  P3 operator*(P_type a) const {
    return P3(x * a, y * a, z * a);
  }

  P3 operator/(P_type a) const {
    return P3(x / a, y / a, z / a);
  }

  P3& operator+=(const P3 &B) {
    x += B.x; y += B.y; z += B.z;
    return *this;
  }

  P3& operator-=(const P3 &B) {
    x -= B.x; y -= B.y; z -= B.z;
    return *this;
  }

  P3& operator*=(P_type a) {
    x *= a; y *= a; z *= a;
    return *this;
  }

  P3& operator/=(P_type a) {
    x /= a; y /= a; z /= a;
    return *this;
  }

  bool operator<(const P3 &b){
    if (abs(x - b. x) > P_eps) return x + P_eps < b.x;
    if (abs(y - b. y) > P_eps) return y + P_eps < b.y;
    return z + P_eps < b.z;
  }
};

/* 3点a, b, cを通る平面 */
// TODO: 1直線上に並んでいる場合をError化
struct Plane {
  P3 a, b, c;

  Plane(P3 a, P3 b, P3 c): a(a), b(b), c(c) {}
};

P_type dot(P3 a, P3 b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}

P3 cross(P3 a, P3 b) {
  P_type x = a.y * b.z - a.z * b.y;
  P_type y = a.z * b.x - a.x * b.z;
  P_type z = a.x * b.y - a.y * b.x;
  return P3(x, y, z);
}

P_type norm(P3 a) {
  return dot(a, a);
}

G_real abs(P3 a) {
  return sqrt(dot(a, a));
}

/* ベクトルa, bの成す角[0, pi] */
G_real arg(P3 a, P3 b) {
  return acos(dot(a, b) / abs(a) / abs(b));
}

/* 直線abと点cの距離 */
G_real distanceLP(P3 a, P3 b, P3 c) {
  return abs(cross(b-a, c-a)) / abs(b-a);
}

/* 線分abと点cの距離 */
G_real distanceSP(P3 a, P3 b, P3 c) {
  if (dot(b-a, c-a) <= P_eps) return abs(c-a);
  if (dot(a-b, c-b) <= P_eps) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

/* 射影(直線abとpからの垂線との交点) */
P3 getProject(P3 a, P3 b, P3 p) {
  P3 base = b - a;
  return a + base * dot(p - a, base) / norm(base);
}

/* 直線Aと直線Bの距離 */
G_real distanceLL(P3 a1, P3 a2, P3 b1, P3 b2) {
  P3 n = cross(a2 - a1, b2 - b1);
  if (abs(n) <= P_eps) return distanceLP(a1, a2, b1); //平行
  return abs(dot(n, b1 - a1)) / abs(n);
}

/* 線分Aと線分Bの距離(未検証) */
G_real distanceSS(P3 a1, P3 a2, P3 b1, P3 b2) {
  //ねじれの位置
  P3 n = cross(a2 - a1, b2 - b1);
  if (abs(n) > P_eps) { // 平行ではない
    G_real d = distanceLL(a1, a2, b1, b2);
    P3 p = n * d / abs(n);
    P3 c1 = b1 + p, c2 = b2 + p;

    P3 va = a2 - a1, vc = c2 - c1;
    bool f1 = dot(cross(va, c1 - a1), cross(va, c2 - a1)) < -P_eps;
    bool f2 = dot(cross(vc, a1 - c1), cross(vc, a2 - c1)) < -P_eps;

    if (f1 && f2) return d;
  }

  //その他
  return min({distanceSP(a1, a2, b1), distanceSP(a1, a2, b2),
              distanceSP(b1, b2, a1), distanceSP(b1, b2, a2)});
}

/* 点と平面Plの距離 */
G_real distancePPl(P3 p, P3 pl1, P3 pl2, P3 pl3) {
  P3 n = cross(pl2 - pl1, pl3 - pl1);
  return abs(dot(p - pl1, n)) / abs(n);
}

/* 直線Aと、平面Plの交点 */
// verified: AOJ0115
vector<P3> getCrosspointLPl(P3 a1, P3 a2, P3 pl1, P3 pl2, P3 pl3) {
  P3 n = cross(pl2 - pl1, pl3 - pl1); //平面の法線ベクトル
  if (abs(dot(n, a2 - a1)) <= P_eps)
    return {}; //平面と直線が平行

  G_real s = dot(pl1 - a1, n), t = dot(a2 - pl1, n);
  P3 c = a1 + (a2 - a1) * (s / (s + t));
  return {c};
}

/* 線分Aと、平面Plの交点 */
// verified: AOJ0115
vector<P3> getCrosspointSPl(P3 a1, P3 a2, P3 pl1, P3 pl2, P3 pl3) {
  auto cps = getCrosspointLPl(a1, a2, pl1, pl2, pl3);
  if (cps.empty()) return {};
  if (norm(a1 - cps[0]) > norm(a1 - a2)) return {};
  if (norm(a2 - cps[0]) > norm(a1 - a2)) return {};
  return cps;
}

P3 scan() {
  double x, y, z;
  cin >> x >> y >> z;
  return P3(x, y, z);
}

int main(){

  while(1) {
    int N, M;
    P3 s[500], t[50];
    double phi[50];

    cin >> N;

    if (!N) break;

    for (int i=0; i<N; i++)
      s[i] = scan();

    cin >> M;

    for (int i=0; i<M; i++) {
      t[i] = scan();
      cin >> phi[i];
    }

    int ans = 0;

    for (int i=0; i<N; i++) {
      bool ok = false;
      for (int j=0; j<M; j++) {
        ok |= arg(s[i], t[j]) < phi[j] + P_eps;
      }
      ans += ok;
    }

    cout << ans << endl;
  }

  return 0;
}


### Prompt

In cpp, your task is to solve the following 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

### Response

```cpp
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* 3次元幾何 */

typedef double P_type;
typedef double G_real; //実数の戻り値(float or double or long double)
const G_real P_eps = 1e-8; //整数の時はゼロ

struct P3{
  P_type x, y, z;
  P3(P_type x = 0, P_type y = 0, P_type z = 0): x(x), y(y), z(z) {}

  P3 operator-() const {
    return P3(-x, -y, -z);
  }

  P3 operator+(const P3 &B) const {
    return P3(x + B.x, y + B.y, z + B.z);
  }

  P3 operator-(const P3 &B) const {
    return P3(x - B.x, y - B.y, z - B.z);
  }

  P3 operator*(P_type a) const {
    return P3(x * a, y * a, z * a);
  }

  P3 operator/(P_type a) const {
    return P3(x / a, y / a, z / a);
  }

  P3& operator+=(const P3 &B) {
    x += B.x; y += B.y; z += B.z;
    return *this;
  }

  P3& operator-=(const P3 &B) {
    x -= B.x; y -= B.y; z -= B.z;
    return *this;
  }

  P3& operator*=(P_type a) {
    x *= a; y *= a; z *= a;
    return *this;
  }

  P3& operator/=(P_type a) {
    x /= a; y /= a; z /= a;
    return *this;
  }

  bool operator<(const P3 &b){
    if (abs(x - b. x) > P_eps) return x + P_eps < b.x;
    if (abs(y - b. y) > P_eps) return y + P_eps < b.y;
    return z + P_eps < b.z;
  }
};

/* 3点a, b, cを通る平面 */
// TODO: 1直線上に並んでいる場合をError化
struct Plane {
  P3 a, b, c;

  Plane(P3 a, P3 b, P3 c): a(a), b(b), c(c) {}
};

P_type dot(P3 a, P3 b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}

P3 cross(P3 a, P3 b) {
  P_type x = a.y * b.z - a.z * b.y;
  P_type y = a.z * b.x - a.x * b.z;
  P_type z = a.x * b.y - a.y * b.x;
  return P3(x, y, z);
}

P_type norm(P3 a) {
  return dot(a, a);
}

G_real abs(P3 a) {
  return sqrt(dot(a, a));
}

/* ベクトルa, bの成す角[0, pi] */
G_real arg(P3 a, P3 b) {
  return acos(dot(a, b) / abs(a) / abs(b));
}

/* 直線abと点cの距離 */
G_real distanceLP(P3 a, P3 b, P3 c) {
  return abs(cross(b-a, c-a)) / abs(b-a);
}

/* 線分abと点cの距離 */
G_real distanceSP(P3 a, P3 b, P3 c) {
  if (dot(b-a, c-a) <= P_eps) return abs(c-a);
  if (dot(a-b, c-b) <= P_eps) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

/* 射影(直線abとpからの垂線との交点) */
P3 getProject(P3 a, P3 b, P3 p) {
  P3 base = b - a;
  return a + base * dot(p - a, base) / norm(base);
}

/* 直線Aと直線Bの距離 */
G_real distanceLL(P3 a1, P3 a2, P3 b1, P3 b2) {
  P3 n = cross(a2 - a1, b2 - b1);
  if (abs(n) <= P_eps) return distanceLP(a1, a2, b1); //平行
  return abs(dot(n, b1 - a1)) / abs(n);
}

/* 線分Aと線分Bの距離(未検証) */
G_real distanceSS(P3 a1, P3 a2, P3 b1, P3 b2) {
  //ねじれの位置
  P3 n = cross(a2 - a1, b2 - b1);
  if (abs(n) > P_eps) { // 平行ではない
    G_real d = distanceLL(a1, a2, b1, b2);
    P3 p = n * d / abs(n);
    P3 c1 = b1 + p, c2 = b2 + p;

    P3 va = a2 - a1, vc = c2 - c1;
    bool f1 = dot(cross(va, c1 - a1), cross(va, c2 - a1)) < -P_eps;
    bool f2 = dot(cross(vc, a1 - c1), cross(vc, a2 - c1)) < -P_eps;

    if (f1 && f2) return d;
  }

  //その他
  return min({distanceSP(a1, a2, b1), distanceSP(a1, a2, b2),
              distanceSP(b1, b2, a1), distanceSP(b1, b2, a2)});
}

/* 点と平面Plの距離 */
G_real distancePPl(P3 p, P3 pl1, P3 pl2, P3 pl3) {
  P3 n = cross(pl2 - pl1, pl3 - pl1);
  return abs(dot(p - pl1, n)) / abs(n);
}

/* 直線Aと、平面Plの交点 */
// verified: AOJ0115
vector<P3> getCrosspointLPl(P3 a1, P3 a2, P3 pl1, P3 pl2, P3 pl3) {
  P3 n = cross(pl2 - pl1, pl3 - pl1); //平面の法線ベクトル
  if (abs(dot(n, a2 - a1)) <= P_eps)
    return {}; //平面と直線が平行

  G_real s = dot(pl1 - a1, n), t = dot(a2 - pl1, n);
  P3 c = a1 + (a2 - a1) * (s / (s + t));
  return {c};
}

/* 線分Aと、平面Plの交点 */
// verified: AOJ0115
vector<P3> getCrosspointSPl(P3 a1, P3 a2, P3 pl1, P3 pl2, P3 pl3) {
  auto cps = getCrosspointLPl(a1, a2, pl1, pl2, pl3);
  if (cps.empty()) return {};
  if (norm(a1 - cps[0]) > norm(a1 - a2)) return {};
  if (norm(a2 - cps[0]) > norm(a1 - a2)) return {};
  return cps;
}

P3 scan() {
  double x, y, z;
  cin >> x >> y >> z;
  return P3(x, y, z);
}

int main(){

  while(1) {
    int N, M;
    P3 s[500], t[50];
    double phi[50];

    cin >> N;

    if (!N) break;

    for (int i=0; i<N; i++)
      s[i] = scan();

    cin >> M;

    for (int i=0; i<M; i++) {
      t[i] = scan();
      cin >> phi[i];
    }

    int ans = 0;

    for (int i=0; i<N; i++) {
      bool ok = false;
      for (int j=0; j<M; j++) {
        ok |= arg(s[i], t[j]) < phi[j] + P_eps;
      }
      ans += ok;
    }

    cout << ans << endl;
  }

  return 0;
}


```