#include <bits/stdc++.h>
struct point {
  double x, y, z;
  point(double _x = 0, double _y = 0, double _z = 0) { x = _x, y = _y, z = _z; }
  void read() { scanf("%lf%lf%lf", &x, &y, &z); }
  double dis() { return x * x + y * y + z * z; }
  friend point operator+(point A, point B) {
    return point(A.x + B.x, A.y + B.y, A.z + B.z);
  }
  friend point operator-(point A, point B) {
    return point(A.x - B.x, A.y - B.y, A.z - B.z);
  }
  friend double operator*(point A, point B) {
    return A.x * B.x + A.y * B.y + A.z * B.z;
  }
} A, V, P, Q;
int R, N;
double ans = 1e9;
void solve(point p, int r) {
  double a = V.dis(), b = V * (A - p) * 2, c = (A - p).dis() - r * r,
         d = b * b - 4 * a * c, x;
  if (d >= 0 && (x = (-b - sqrt(d)) / a / 2) > 0) ans = std::min(ans, x);
}
void doit() {
  A.read(), V.read(), scanf("%d%d", &R, &N);
  for (int i = 1, r, m; i <= N; i++) {
    P.read(), scanf("%d%d", &r, &m), solve(P, R + r);
    for (; m; m--) Q.read(), solve(P + Q, R);
  }
  if (ans == 1e9)
    puts("-1");
  else
    printf("%.9lf\n", ans);
}
int main() {
  doit();
  return 0;
}
