#include <bits/stdc++.h>
const double pi = 3.1415926535897932384626433832795, eps = 1e-10;
int N, M, i, j;
double Ax, Ay, Az, Vx, Vy, Vz, Ox, Oy, Oz, Bx, By, Bz, px, py, pz, R, r, Sin,
    Sin1, Theta, Theta1, Theta2, l1, l2, mid1, mid2, h, s, Len, Ans, d, D, Cos;
double len(double x, double y, double z) { return sqrt(x * x + y * y + z * z); }
double Get(double x) {
  double Px, Py, Pz;
  Px = Ox + px / Len * x, Py = Oy + py / Len * x, Pz = Oz + pz / Len * x;
  return len(Px - Ax, Py - Ay, Pz - Az);
}
double Abs(double x) {
  if (x < 0) return -x;
  return x;
}
int main() {
  scanf("%lf%lf%lf%lf%lf%lf%lf", &Ax, &Ay, &Az, &Vx, &Vy, &Vz, &R);
  scanf("%d", &N);
  Ans = 1e63;
  for (i = 1; i <= N; ++i) {
    scanf("%lf%lf%lf%lf%d", &Ox, &Oy, &Oz, &r, &M);
    if (Abs(Ox - Ax) < eps && Abs(Oy - Ay) < eps && Abs(Oz - Az) < eps)
      d = D = 0;
    else {
      Bx = Ox - Ax, By = Oy - Ay, Bz = Oz - Az;
      l1 = len(Vx, Vy, Vz), l2 = len(Bx, By, Bz);
      Cos = (Vx * Bx + Vy * By + Vz * Bz) / l1 / l2;
      if (Cos < 0)
        d = len(Ax - Ox, Ay - Oy, Az - Oz), D = 0;
      else {
        Sin = sqrt(1 - Cos * Cos), d = l2 * Sin;
        if (Sin > 1) Sin = 1;
        if (Sin < eps)
          D = l2 - R - r;
        else {
          if (d - eps < R + r) {
            Sin1 = Sin * l2 / (R + r);
            if (Sin1 > 1) Sin1 = 1;
            Theta = asin(Sin);
            Theta1 = pi - asin(Sin1);
            Theta2 = pi - Theta - Theta1;
            D = sin(Theta2) * (R + r) / Sin;
          } else
            D = 1e63;
        }
      }
    }
    if (d - eps < R + r)
      if (D < Ans) Ans = D;
    for (j = 1; j <= M; ++j) {
      scanf("%lf%lf%lf", &px, &py, &pz);
      Len = len(px, py, pz);
      for (h = 0, s = Len; h + eps < s;) {
        mid1 = h + (s - h) / 3, mid2 = h + (s - h) / 3 * 2;
        l1 = Get(mid1), l2 = Get(mid2);
        if (l1 < l2)
          s = mid2;
        else
          h = mid1;
      }
      px = Ox + px / Len * h, py = Oy + py / Len * h, pz = Oz + pz / Len * h,
      r = 0;
      if (Abs(px - Ax) < eps && Abs(py - Ay) < eps && Abs(pz - Az) < eps)
        d = D = 0;
      else {
        Bx = px - Ax, By = py - Ay, Bz = pz - Az;
        l1 = len(Vx, Vy, Vz), l2 = len(Bx, By, Bz);
        Cos = (Vx * Bx + Vy * By + Vz * Bz) / l1 / l2;
        if (Cos < 0)
          d = len(Ax - px, Ay - py, Az - pz), D = 0;
        else {
          Sin = sqrt(1 - Cos * Cos), d = l2 * Sin;
          if (Sin > 1) Sin = 1;
          if (Sin < eps)
            D = l2 - R - r;
          else if (d - eps < R + r) {
            Sin1 = Sin * l2 / (R + r);
            if (Sin1 > 1) Sin1 = 1;
            Theta = asin(Sin);
            Theta1 = pi - asin(Sin1);
            Theta2 = pi - Theta - Theta1;
            D = sin(Theta2) * (R + r) / Sin;
          } else
            D = 1e63;
        }
      }
      if (d - eps < R + r)
        if (D < Ans) Ans = D;
    }
  }
  if (Ans > 1e62)
    printf("-1\n");
  else
    printf("%.9lf\n", Ans / len(Vx, Vy, Vz));
  return 0;
}
