#include <bits/stdc++.h>
const int magicconst = 73743071;
using namespace std;
int main() {
  int cx, cy, cz;
  int vx, vy, vz;
  int R;
  scanf("%d%d%d%d%d%d%d", &cx, &cy, &cz, &vx, &vy, &vz, &R);
  vx *= -1;
  vy *= -1;
  vz *= -1;
  int n;
  scanf("%d", &n);
  vector<double> v;
  double a = ((vx) * (vx)) + ((vy) * (vy)) + ((vz) * (vz)), b, c;
  double res = 1e100;
  for (int i = 0; i < (int)(n); ++i) {
    int ox, oy, oz, r, m;
    scanf("%d%d%d%d%d", &ox, &oy, &oz, &r, &m);
    c = ((cx - ox) * (cx - ox)) + ((cy - oy) * (cy - oy)) +
        ((cz - oz) * (cz - oz)) - ((r + R) * (r + R));
    b = 2 * (vx * (ox - cx) + vy * (oy - cy) + vz * (oz - cz));
    if (((b) * (b)) >= 4 * a * c) {
      double x1 = (-b - sqrt(((b) * (b)) - 4 * a * c)) / 2 / a;
      double x2 = (-b + sqrt(((b) * (b)) - 4 * a * c)) / 2 / a;
      if (x1 >= 0) res = min(res, x1);
      if (x2 >= 0) res = min(res, x2);
    }
    for (int j = 0; j < (int)(m); ++j) {
      int px, py, pz;
      scanf("%d%d%d", &px, &py, &pz);
      c = ((cx - ox - px) * (cx - ox - px)) +
          ((cy - oy - py) * (cy - oy - py)) +
          ((cz - oz - pz) * (cz - oz - pz)) - ((R) * (R));
      b = 2 * (vx * (ox + px - cx) + vy * (oy + py - cy) + vz * (oz + pz - cz));
      if (((b) * (b)) >= 4 * a * c) {
        double x1 = (-b - sqrt(((b) * (b)) - 4 * a * c)) / 2 / a;
        double x2 = (-b + sqrt(((b) * (b)) - 4 * a * c)) / 2 / a;
        if (x1 >= 0) res = min(res, x1);
        if (x2 >= 0) res = min(res, x2);
      }
    }
  }
  if (res > 1e90)
    printf("-1");
  else
    printf("%.9lf\n", res);
  return 0;
}
