#include <bits/stdc++.h>
long long oix[110], oiy[110], oiz[110], r[110], xx[110][110], yy[110][110],
    zz[110][110];
int m[110];
long long ax, ay, az, vx, vy, vz;
double min(double a, double b) {
  if (b < 0) return a;
  if (a < 0) return b;
  return a < b ? a : b;
}
double cal(double x2, double y2, double z2, double dis) {
  double A = 1.0 * vx * vx + 1.0 * vy * vy + 1.0 * vz * vz;
  double B = 2.0 * vx * (ax - x2) + 2.0 * vy * (ay - y2) + 2.0 * vz * (az - z2);
  double C = (ax - x2) * (ax - x2) + (ay - y2) * (ay - y2) +
             (az - z2) * (az - z2) - dis * dis;
  if (B * B < 4 * A * C - 1e-10) return -100;
  double ans1 = (-B - sqrt(B * B - 4 * A * C)) / (2 * A);
  double ans2 = (-B + sqrt(B * B - 4 * A * C)) / (2 * A);
  if (ans2 < -1e-10) return -100;
  if (ans1 < -1e-10) return ans2;
  return ans1;
}
int main() {
  long long R;
  while (scanf("%I64d", &ax) == 1) {
    scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &ay, &az, &vx, &vy, &vz, &R);
    int n;
    scanf("%d", &n);
    double ans = -100;
    for (int i = 0; i < n; i++) {
      scanf("%I64d%I64d%I64d%I64d%Id", &oix[i], &oiy[i], &oiz[i], &r[i], &m[i]);
      double tnum = cal(oix[i], oiy[i], oiz[i], r[i] + R);
      ans = min(ans, tnum);
      for (int j = 0; j < m[i]; j++) {
        long long vx, vy, vz;
        scanf("%I64d%I64d%I64d", &vx, &vy, &vz);
        xx[i][j] = oix[i] + vx;
        yy[i][j] = oiy[i] + vy;
        zz[i][j] = oiz[i] + vz;
        double tnum = cal(xx[i][j], yy[i][j], zz[i][j], R);
        ans = min(ans, tnum);
      }
    }
    if (ans < 0)
      puts("-1");
    else
      printf("%.10f\n", ans);
  }
  return 0;
}
