#include <bits/stdc++.h>
using namespace std;
struct Point {
  double x, y, z;
};
struct ball {
  double x, y, z, r;
  vector<Point> a;
} p[1000], v;
int main() {
  int n;
  scanf("%lf%lf%lf%lf%lf%lf%lf", &p[0].x, &p[0].y, &p[0].z, &v.x, &v.y, &v.z,
        &p[0].r);
  scanf("%d", &n);
  for (int i = 1, m; i <= n; i++) {
    scanf("%lf%lf%lf%lf%d", &p[i].x, &p[i].y, &p[i].z, &p[i].r, &m);
    p[i].r += p[0].r;
    while (m--) {
      double x, y, z;
      scanf("%lf%lf%lf", &x, &y, &z);
      p[i].a.push_back((Point){x + p[i].x, y + p[i].y, z + p[i].z});
    }
  }
  double ans = 1e9 + 7;
  for (int i = 1; i <= n; i++) {
    double A = v.x * v.x + v.y * v.y + v.z * v.z;
    double B = 2 * ((p[0].x - p[i].x) * v.x + (p[0].y - p[i].y) * v.y +
                    (p[0].z - p[i].z) * v.z);
    double C = (p[0].x - p[i].x) * (p[0].x - p[i].x) +
               (p[0].y - p[i].y) * (p[0].y - p[i].y) +
               (p[0].z - p[i].z) * (p[0].z - p[i].z) - p[i].r * p[i].r;
    double D = B * B - 4 * A * C;
    if (D >= 0) {
      double x1 = (-B - sqrt(D)) / (2 * A);
      double x2 = (-B + sqrt(D)) / (2 * A);
      if (x1 > 0) ans = min(ans, x1);
      if (x2 > 0) ans = min(ans, x2);
    }
    for (int j = 0; j < p[i].a.size(); j++) {
      Point b = p[i].a[j];
      A = v.x * v.x + v.y * v.y + v.z * v.z;
      B = 2 *
          ((p[0].x - b.x) * v.x + (p[0].y - b.y) * v.y + (p[0].z - b.z) * v.z);
      C = (p[0].x - b.x) * (p[0].x - b.x) + (p[0].y - b.y) * (p[0].y - b.y) +
          (p[0].z - b.z) * (p[0].z - b.z) - p[0].r * p[0].r;
      D = B * B - 4 * A * C;
      if (D >= 0) {
        double x1 = (-B - sqrt(D)) / (2 * A);
        double x2 = (-B + sqrt(D)) / (2 * A);
        if (x1 > 0) ans = min(ans, x1);
        if (x2 > 0) ans = min(ans, x2);
      }
    }
  }
  if (ans >= 1e9)
    puts("-1");
  else
    printf("%0.10lf\n", ans);
  return 0;
}
