#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
double ax, ay, az, vx, vy, vz, R, r, ox, oy, oz, px, py, pz;
double root(double x, double y, double z, double r) {
  double a = vx * vx + vy * vy + vz * vz;
  double b = 2 * ((ax - x) * vx + (ay - y) * vy + (az - z) * vz);
  double c = (ax - x) * (ax - x) + (ay - y) * (ay - y) + (az - z) * (az - z) -
             (r + R) * (r + R);
  double det = b * b - 4 * a * c;
  if (det < 0) return 10000000000.0;
  double x1 = (-b + sqrt(det)) / (2.0 * a), x2 = (-b - sqrt(det)) / (2.0 * a);
  double minx = min(x1, x2), maxx = max(x1, x2);
  if (minx < 0) {
    if (maxx < 0) return 10000000000.0;
    return maxx;
  }
  return minx;
}
int main() {
  scanf("%lf%lf%lf%lf%lf%lf%lf", &ax, &ay, &az, &vx, &vy, &vz, &R);
  double ans = 2000000000.0;
  int n, m;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lf%lf%lf%lf%d", &ox, &oy, &oz, &r, &m);
    ans = min(ans, root(ox, oy, oz, r));
    for (int j = 1; j <= m; j++) {
      scanf("%lf%lf%lf", &px, &py, &pz);
      px += ox;
      py += oy;
      pz += oz;
      ans = min(ans, root(px, py, pz, 0));
    }
  }
  if (ans > 1000000000.0) {
    puts("-1");
    return 0;
  }
  printf("%.8f\n", ans);
  return 0;
}
