#include <bits/stdc++.h>
using namespace std;
struct Point {
  double X, Y, Z;
  void Get() { scanf("%lf%lf%lf", &X, &Y, &Z); }
};
Point operator-(Point A, Point B) {
  return (Point){A.X - B.X, A.Y - B.Y, A.Z - B.Z};
}
double operator*(Point A, Point B) { return A.X * B.X + A.Y * B.Y + A.Z * B.Z; }
const double inf = 1e9;
const double eps = 1e-6;
double Solve(Point A, Point V, double R) {
  double a = V * V, b = A * V * 2, c = A * A - R * R;
  double Delta = b * b - 4 * a * c;
  if (Delta < -eps) return inf;
  Delta = sqrt(fabs(Delta));
  double T0 = (-b + Delta) / (2 * a), T1 = (-b - Delta) / (2 * a);
  return (T0 < 0) ? inf : ((T1 < 0) ? T0 : T1);
}
int main() {
  Point O, V;
  O.Get();
  V.Get();
  double R, Ans = inf;
  scanf("%lf", &R);
  int N;
  scanf("%d", &N);
  while (N--) {
    Point _O;
    _O.Get();
    double r;
    scanf("%lf", &r);
    Ans = min(Ans, Solve(O - _O, V, R + r));
    int M;
    scanf("%d", &M);
    while (M--) {
      Point Delta;
      Delta.Get();
      Ans = min(Ans, Solve(O - _O - Delta, V, R));
    }
  }
  if (Ans == inf)
    printf("-1\n");
  else
    printf("%0.10lf\n", Ans);
  return 0;
}
