Problem: Once upon a time in the galaxy of far, far away...

Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the Death Star.

When the rebels learnt that the Death Star was coming, they decided to use their new secret weapon — space mines. Let's describe a space mine's build.

Each space mine is shaped like a ball (we'll call it the mine body) of a certain radius r with the center in the point O. Several spikes protrude from the center. Each spike can be represented as a segment, connecting the center of the mine with some point P, such that <image> (transporting long-spiked mines is problematic), where |OP| is the length of the segment connecting O and P. It is convenient to describe the point P by a vector p such that P = O + p.

The Death Star is shaped like a ball with the radius of R (R exceeds any mine's radius). It moves at a constant speed along the v vector at the speed equal to |v|. At the moment the rebels noticed the Star of Death, it was located in the point A.

The rebels located n space mines along the Death Star's way. You may regard the mines as being idle. The Death Star does not know about the mines' existence and cannot notice them, which is why it doesn't change the direction of its movement. As soon as the Star of Death touched the mine (its body or one of the spikes), the mine bursts and destroys the Star of Death. A touching is the situation when there is a point in space which belongs both to the mine and to the Death Star. It is considered that Death Star will not be destroyed if it can move infinitely long time without touching the mines.

Help the rebels determine whether they will succeed in destroying the Death Star using space mines or not. If they will succeed, determine the moment of time when it will happen (starting from the moment the Death Star was noticed).

Input

The first input data line contains 7 integers Ax, Ay, Az, vx, vy, vz, R. They are the Death Star's initial position, the direction of its movement, and its radius ( - 10 ≤ vx, vy, vz ≤ 10, |v| > 0, 0 < R ≤ 100).

The second line contains an integer n, which is the number of mines (1 ≤ n ≤ 100). Then follow n data blocks, the i-th of them describes the i-th mine.

The first line of each block contains 5 integers Oix, Oiy, Oiz, ri, mi, which are the coordinates of the mine centre, the radius of its body and the number of spikes (0 < ri < 100, 0 ≤ mi ≤ 10). Then follow mi lines, describing the spikes of the i-th mine, where the j-th of them describes the i-th spike and contains 3 integers pijx, pijy, pijz — the coordinates of the vector where the given spike is directed (<image>).

The coordinates of the mines' centers and the center of the Death Star are integers, their absolute value does not exceed 10000. It is guaranteed that R > ri for any 1 ≤ i ≤ n. For any mines i ≠ j the following inequality if fulfilled: <image>. Initially the Death Star and the mines do not have common points.

Output

If the rebels will succeed in stopping the Death Star using space mines, print the time from the moment the Death Star was noticed to the blast.

If the Death Star will not touch a mine, print "-1" (without quotes).

For the answer the absolute or relative error of 10 - 6 is acceptable.

Examples

Input

0 0 0 1 0 0 5
2
10 8 0 2 2
0 -3 0
2 2 0
20 0 0 4 3
2 4 0
-4 3 0
1 -5 0


Output

10.0000000000

Input

8 8 4 4 4 2 6
1
-2 -2 -1 3 0


Output

-1

Input

30 30 2 1 2 1 20
3
0 0 40 5 1
1 4 4
-10 -40 -5 7 0
100 200 95 8 1
-10 0 0


Output

74.6757620881

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
const double eps = 1e-8;
const double PI = atan2(0.0, -1.0);
inline double sqr(double x) { return x * x; }
inline bool zero(double x) { return (x > 0 ? x : -x) < eps; }
inline int sgn(double x) { return (x > eps ? 1 : (x + eps < 0 ? -1 : 0)); }
struct point3 {
  double x, y, z;
  point3(double x, double y, double z) : x(x), y(y), z(z) {}
  point3() {}
  bool operator==(const point3& a) const {
    return sgn(x - a.x) == 0 && sgn(y - a.y) == 0 && sgn(z - a.z) == 0;
  }
  bool operator!=(const point3& a) const {
    return sgn(x - a.x) != 0 || sgn(y - a.y) != 0 || sgn(z - a.z) != 0;
  }
  bool operator<(const point3& a) const {
    return sgn(x - a.x) < 0 || sgn(x - a.x) == 0 && sgn(y - a.y) < 0 ||
           sgn(x - a.x) == 0 && sgn(y - a.y) == 0 && sgn(z - a.z) < 0;
  }
  point3 operator+(const point3& a) const {
    return point3(x + a.x, y + a.y, z + a.z);
  }
  point3 operator-(const point3& a) const {
    return point3(x - a.x, y - a.y, z - a.z);
  }
  point3 operator*(const double& a) const {
    return point3(x * a, y * a, z * a);
  }
  point3 operator/(const double& a) const {
    return point3(x / a, y / a, z / a);
  }
  point3 operator*(const point3& a) const {
    return point3(y * a.z - z * a.y, z * a.x - x * a.z, x * a.y - y * a.x);
  }
  double operator^(const point3& a) const {
    return x * a.x + y * a.y + z * a.z;
  }
  double sqrlen() const { return sqr(x) + sqr(y) + sqr(z); }
  double length() const { return sqrt(sqrlen()); }
  point3 trunc(double a) const { return (*this) * (a / length()); }
  point3 rotate(const point3& a, const point3& b, const point3& c) const {
    return point3(a ^ (*this), b ^ (*this), c ^ (*this));
  }
};
inline point3 pvec(const point3& a, const point3& b, const point3& c) {
  return (a - b) * (b - c);
}
inline bool dotsInline(const point3& a, const point3& b, const point3& c) {
  return zero(((a - b) * (b - c)).length());
}
inline bool dotOnlineIn(const point3& p, const point3& l1, const point3& l2) {
  return zero(((p - l1) * (p - l2)).length()) &&
         (l1.x - p.x) * (l2.x - p.x) < eps &&
         (l1.y - p.y) * (l2.y - p.y) < eps && (l1.z - p.z) * (l2.z - p.z) < eps;
}
inline int decideSide(const point3& p1, const point3& p2, const point3& l1,
                      const point3& l2) {
  return sgn(((l1 - l2) * (p1 - l2)) ^ ((l1 - l2) * (p2 - l2)));
}
inline int decideSide(const point3& p1, const point3& p2, const point3& a,
                      const point3& b, const point3& c) {
  return sgn((pvec(a, b, c) ^ (p1 - a)) * (pvec(a, b, c) ^ (p2 - a)));
}
inline bool parallel(const point3& u1, const point3& u2, const point3& v1,
                     const point3& v2) {
  return zero(((u1 - u2) * (v1 - v2)).length());
}
inline bool parallel(const point3& a, const point3& b, const point3& c,
                     const point3& d, const point3& e, const point3& f) {
  return zero((pvec(a, b, c) * pvec(d, e, f)).length());
}
inline bool parallel(const point3& l1, const point3& l2, const point3& a,
                     const point3& b, const point3& c) {
  return zero((l1 - l2) ^ pvec(a, b, c));
}
point3 intersection(const point3& l1, const point3& l2, const point3& a,
                    const point3& b, const point3& c) {
  point3 temp = pvec(a, b, c);
  return l1 + (l2 - l1) * ((temp ^ (a - l1)) / (temp ^ (l2 - l1)));
}
void intersection(const point3& a, const point3& b, const point3& c,
                  const point3& d, const point3& e, const point3& f, point3& p1,
                  point3& p2) {
  p1 = parallel(d, e, a, b, c) ? intersection(e, f, a, b, c)
                               : intersection(d, e, a, b, c);
  p2 = parallel(f, d, a, b, c) ? intersection(e, f, a, b, c)
                               : intersection(f, d, a, b, c);
}
inline point3 ptoline(const point3& p, const point3& l1, const point3& l2) {
  point3 temp = l2 - l1;
  return l1 + temp * ((p - l1) ^ temp) / (temp ^ temp);
}
inline point3 ptoplane(const point3& p, const point3& a, const point3& b,
                       const point3& c) {
  return intersection(p, p + pvec(a, b, c), a, b, c);
}
inline double dislinetoline(const point3& u1, const point3& u2,
                            const point3& v1, const point3& v2) {
  point3 temp = (u1 - u2) * (v1 - v2);
  return fabs((u1 - v1) ^ temp) / temp.length();
}
void linetoline(const point3& u1, const point3& u2, const point3& v1,
                const point3& v2, point3& p1, point3& p2) {
  point3 ab = u2 - u1, cd = v2 - v1, ac = v1 - u1;
  p2 = v1 + cd * (((ab ^ cd) * (ac ^ ab) - (ab ^ ab) * (ac ^ cd)) /
                  ((ab ^ ab) * (cd ^ cd) - sqr(ab ^ cd)));
  p1 = ptoline(p2, u1, u2);
}
const double EPS = 1e-8;
const double INF = 1e6;
double gao(const point3& u, const point3& v, double r) {
  double a = (v ^ v);
  double b = 2 * (u ^ v);
  double c = (u ^ u) - r * r;
  double d = b * b - 4 * a * c;
  if (d < -EPS) {
    return INF;
  }
  d = sqrt(max(0.0, d));
  double t1 = (-b - d) / (2 * a);
  double t2 = (-b + d) / (2 * a);
  if (t1 > t2) {
    swap(t1, t2);
  }
  if (t1 > -EPS) {
    return t1;
  } else if (t2 > -EPS) {
    return t2;
  } else {
    return INF;
  }
}
double dis(const point3& a, const point3& b, const point3& c) {
  if (dotOnlineIn(c, a, b)) {
    return 0.0;
  } else {
    return min((c - a).length(), (c - b).length());
  }
}
double gao(point3 a, point3 b, point3 c, point3 d) {
  double ret = min(min((c - a).length(), (d - a).length()),
                   min((c - b).length(), (d - b).length()));
  double tmp = dislinetoline(a, b, c, d);
  if (parallel(a, b, c, d)) {
    c = ptoline(c, a, b);
    d = ptoline(d, a, b);
    ret = min(ret, hypot(tmp, dis(a, b, c)));
    ret = min(ret, hypot(tmp, dis(a, b, d)));
    ret = min(ret, hypot(tmp, dis(c, d, a)));
    ret = min(ret, hypot(tmp, dis(c, d, b)));
  } else {
    point3 u, v;
    linetoline(a, b, c, d, u, v);
    if (dotOnlineIn(u, a, b) && dotOnlineIn(v, c, d)) {
      ret = min(ret, dislinetoline(a, b, c, d));
    }
    u = ptoline(a, c, d);
    if (dotOnlineIn(u, c, d)) {
      ret = min(ret, (a - u).length());
    }
    u = ptoline(b, c, d);
    if (dotOnlineIn(u, c, d)) {
      ret = min(ret, (b - u).length());
    }
    u = ptoline(c, a, b);
    if (dotOnlineIn(u, a, b)) {
      ret = min(ret, (c - u).length());
    }
    u = ptoline(d, a, b);
    if (dotOnlineIn(u, a, b)) {
      ret = min(ret, (d - u).length());
    }
  }
  return ret;
}
int main() {
  int n, m, p;
  point3 a[200], b[10000], c[1000], v;
  double r[200], lo = 0, up = INF;
  scanf("%lf%lf%lf%lf%lf%lf%lf", &a[0].x, &a[0].y, &a[0].z, &v.x, &v.y, &v.z,
        &r[0]);
  scanf("%d", &n);
  m = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%lf%lf%lf%lf%d", &a[i].x, &a[i].y, &a[i].z, &r[i], &p);
    up = min(up, gao(a[0] - a[i], v, r[0] + r[i]));
    for (int j = 0; j < p; ++j) {
      scanf("%lf%lf%lf", &c[m].x, &c[m].y, &c[m].z);
      b[m] = a[i];
      c[m] = b[m] + c[m];
      ++m;
    }
  }
  for (int tt = 0; tt < 1000; ++tt) {
    double mid = (lo + up) / 2;
    point3 aa = a[0] + v * mid;
    bool flag = true;
    for (int i = 0; flag && i < m; ++i) {
      if (gao(a[0], aa, b[i], c[i]) <= r[0]) {
        flag = false;
      }
    }
    if (flag) {
      lo = mid;
    } else {
      up = mid;
    }
  }
  lo = (lo + up) / 2;
  if (lo > INF / 2) {
    puts("-1");
  } else {
    printf("%.10lf\n", lo);
  }
  return 0;
}