#include <bits/stdc++.h>
using namespace std;
int Nextint() {
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  int x = 0;
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
double Ax, Ay, Az, Vx, Vy, Vz, R;
double px, py, pz, r;
double ans;
double get() {
  double A = Vx * Vx + Vy * Vy + Vz * Vz;
  double B = -(Vx * px + Vy * py + Vz * pz) * 2;
  double C = px * px + py * py + pz * pz - r * r;
  double D = B * B - 4 * A * C;
  if (D < 0 || -B - sqrt(D) < 0) return 1E30;
  return (-B - sqrt(D)) / 2 / A;
}
int main() {
  ans = 1E30;
  scanf("%lf%lf%lf%lf%lf%lf%lf", &Ax, &Ay, &Az, &Vx, &Vy, &Vz, &R);
  int N = Nextint();
  for (int i = 1; i <= N; i++) {
    double ox, oy, oz;
    int M;
    scanf("%lf%lf%lf%lf%d", &ox, &oy, &oz, &r, &M);
    px = ox - Ax;
    py = oy - Ay;
    pz = oz - Az;
    r += R;
    ans = min(ans, get());
    r = R;
    for (int j = 1; j <= M; j++) {
      scanf("%lf%lf%lf", &px, &py, &pz);
      px += ox - Ax;
      py += oy - Ay;
      pz += oz - Az;
      ans = min(ans, get());
    }
  }
  if (ans < 1E20)
    printf("%.10lf\n", ans);
  else
    printf("-1\n");
  return 0;
}
