#include <bits/stdc++.h>
using namespace std;
double Ax, Ay, Az, Vx, Vy, Vz, R, Ans, r[110];
double Ox[110], Oy[110], Oz[110], Px[110][11], Py[110][11], Pz[110][11];
int N, i, j, M[110];
void Calc(double X, double Y, double Z, double r) {
  double A = ((Vx) * (Vx)) + ((Vy) * (Vy)) + ((Vz) * (Vz));
  double B = 2 * (Ax - X) * Vx + 2 * (Ay - Y) * Vy + 2 * (Az - Z) * Vz;
  double C = ((Ax - X) * (Ax - X)) + ((Ay - Y) * (Ay - Y)) +
             ((Az - Z) * (Az - Z)) - ((R + r) * (R + r));
  double D = ((B) * (B)) - 4 * A * C;
  if (D < 0) return;
  double R1 = (-B - sqrt(D)) / (2. * A), R2 = (-B + sqrt(D)) / (2. * A);
  if (R1 >= 0 && R1 < Ans) Ans = R1;
  if (R2 >= 0 && R2 < Ans) Ans = R2;
}
void work() {
  Ans = 1E30;
  for (i = 1; i <= N; i++) {
    Calc(Ox[i], Oy[i], Oz[i], r[i]);
    for (j = 1; j <= M[i]; j++)
      Calc(Ox[i] + Px[i][j], Oy[i] + Py[i][j], Oz[i] + Pz[i][j], 0);
  }
  if (Ans >= 1E20)
    puts("-1");
  else
    printf("%.10lf\n", Ans);
}
int main() {
  scanf("%lf%lf%lf%lf%lf%lf%lf%d", &Ax, &Ay, &Az, &Vx, &Vy, &Vz, &R, &N);
  for (i = 1; i <= N; i++) {
    scanf("%lf%lf%lf%lf%d", &Ox[i], &Oy[i], &Oz[i], &r[i], &M[i]);
    for (j = 1; j <= M[i]; j++)
      scanf("%lf%lf%lf", &Px[i][j], &Py[i][j], &Pz[i][j]);
  }
  work();
  return 0;
}
