#include <bits/stdc++.h>
using namespace std;
const int maxn = 5001;
struct point {
  double x, y, z;
  point() {}
  point(double i, double j, double k) : x(i), y(j), z(k) {}
  void input() { scanf("%lf%lf%lf", &x, &y, &z); }
  point operator+(point i) { return point(x + i.x, y + i.y, z + i.z); }
  point operator-(point i) { return point(x - i.x, y - i.y, z - i.z); }
  double dis() { return x * x + y * y + z * z; }
} a, v, o, p;
double r0, r;
int n, m;
double sqr(double x) { return x * x; }
double solve(point d, double r) {
  double a, b, c;
  a = v.dis();
  b = 2 * (v.x * d.x + v.y * d.y + v.z * d.z);
  c = d.dis() - sqr(r);
  c = sqr(b) - 4 * a * c;
  if (c < 0) return 1e10;
  double x = (b - sqrt(c)) / 2 / a;
  if (x < 0) return 1e10;
  return x;
}
int main() {
  int k;
  double t;
  a.input();
  v.input();
  scanf("%lf", &r0);
  scanf("%d", &n);
  t = 1e10;
  while (n--) {
    o.input();
    scanf("%lf", &r);
    o = o - a;
    t = min(t, solve(o, r0 + r));
    scanf("%d", &k);
    while (k--) {
      p.input();
      t = min(t, solve(o + p, r0));
    }
  }
  if (t > 9e9)
    printf("-1\n");
  else
    printf("%.10f\n", t);
  return 0;
}
