#include <bits/stdc++.h>
using namespace std;
double x[1005], y[1005], z[1005], r[1005];
long long int n, m;
int main() {
  double res = (1ll << (long long int)(60)), ax, ay, az, vx, vy, vz, R;
  cin >> ax >> ay >> az >> vx >> vy >> vz >> R >> n;
  for (long long int i = 0; i < ((long long int)(n)); i++) {
    cin >> x[0] >> y[0] >> z[0] >> r[0] >> m;
    for (long long int j = 0; j < ((long long int)(m)); j++)
      cin >> x[j + 1] >> y[j + 1] >> z[j + 1];
    for (long long int j = 0; j < ((long long int)(m)); j++)
      x[j + 1] += x[0], y[j + 1] += y[0], z[j + 1] += z[0];
    for (long long int j = 0; j < ((long long int)(m + 1)); j++) {
      double t = -(vx * (ax - x[j]) + vy * (ay - y[j]) + vz * (az - z[j])) /
                 ((vx) * (vx) + (vy) * (vy) + (vz) * (vz));
      if (t < 0) continue;
      if (((vx * t + ax - x[j]) * (vx * t + ax - x[j]) +
           (vy * t + ay - y[j]) * (vy * t + ay - y[j]) +
           (vz * t + az - z[j]) * (vz * t + az - z[j])) <
          (R + r[j]) * (R + r[j]) + 0.0000001) {
        double low = 0, high = t;
        for (long long int k = 0; k < ((long long int)(100)); k++) {
          double mid = (low + high) / 2.0;
          if (((vx * mid + ax - x[j]) * (vx * mid + ax - x[j]) +
               (vy * mid + ay - y[j]) * (vy * mid + ay - y[j]) +
               (vz * mid + az - z[j]) * (vz * mid + az - z[j])) <
              (R + r[j]) * (R + r[j]))
            high = mid;
          else
            low = mid;
        }
        res = min(res, low);
      }
    }
  }
  if (res == (1ll << (long long int)(60)))
    cout << "-1" << endl;
  else
    printf("%0.20lf\n", res);
}
