#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 10;
const double inf = 1e18, eps = 1e-7;
struct vec {
  double x, y, z;
  vec(double _x = 0, double _y = 0, double _z = 0) : x(_x), y(_y), z(_z) {}
  void read() { scanf("%lf%lf%lf", &x, &y, &z); }
  void operator+=(const vec &A) {
    x += A.x;
    y += A.y;
    z += A.z;
  }
  void operator-=(const vec &A) {
    x -= A.x;
    y -= A.y;
    z -= A.z;
  }
};
vec A, v;
double R;
int n;
vec O;
double r;
vec P;
double ans = inf;
inline double sqr(double x) { return x * x; }
double calc(vec O, double R) {
  double a = sqr(v.x) + sqr(v.y) + sqr(v.z),
         b = -(v.x * O.x + v.y * O.y + v.z * O.z),
         c = sqr(O.x) + sqr(O.y) + sqr(O.z) - sqr(R);
  if (sqr(b) - a * c < 0) return inf;
  double t = (-b - sqrt(sqr(b) - a * c)) / a;
  if (t < -eps) return inf;
  return t;
}
int main() {
  A.read();
  v.read();
  scanf("%lf", &R);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    O.read();
    O -= A;
    int m;
    scanf("%lf%d", &r, &m);
    ans = min(ans, calc(O, R + r));
    while (m--) {
      P.read();
      P += O;
      ans = min(ans, calc(P, R));
    }
  }
  if (ans == inf)
    puts("-1");
  else
    printf("%.12lf\n", ans);
}
