#include <bits/stdc++.h>
const double zero = 1e-8, max = 1e9;
int ax, ay, az, vx, vy, vz;
double t;
void check(int x, int y, int z, int d) {
  double x0 = x - ax, y0 = y - ay, z0 = z - az;
  long double a = vx * vx + vy * vy + vz * vz,
              b = 2 * (x0 * vx + y0 * vy + z0 * vz),
              c = x0 * x0 + y0 * y0 + z0 * z0 - d * d;
  long double delta = b * b - 4 * a * c;
  long double temp;
  if (fabs(delta) < zero)
    temp = 0.0;
  else if (delta < 0)
    return;
  else
    temp = sqrt(delta);
  long double x1 = (b - temp) / a / 2.0;
  long double x2 = (b + temp) / a / 2.0;
  if (x1 > 0)
    if (x1 < t) t = x1;
  if (x2 > 0)
    if (x2 < t) t = x2;
}
int main() {
  int n, m, R, r, ox, oy, oz, px, py, pz, i, j;
  scanf("%d %d %d", &ax, &ay, &az);
  scanf("%d %d %d", &vx, &vy, &vz);
  scanf("%d", &R);
  scanf("%d", &n);
  t = max;
  while (n--) {
    scanf("%d %d %d %d %d", &ox, &oy, &oz, &r, &m);
    check(ox, oy, oz, r + R);
    while (m--) {
      scanf("%d %d %d", &px, &py, &pz);
      px += ox;
      py += oy;
      pz += oz;
      check(px, py, pz, R);
    }
  }
  if (fabs(t - max) < zero)
    printf("-1");
  else
    printf("%.10lf", t);
  return (0);
}
