#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y, z;
  point operator+(point b) {
    point t;
    t.x = x + b.x;
    t.y = y + b.y;
    t.z = z + b.z;
    return t;
  }
  point operator-(point b) {
    point t;
    t.x = x - b.x;
    t.y = y - b.y;
    t.z = z - b.z;
    return t;
  }
  double operator*(point b) { return x * b.x + y * b.y + z * b.z; }
};
point O, V;
double ct(point p, double dis) {
  point t;
  t = p - O;
  double a, b, c, d, t1, t2;
  a = V * V;
  b = -2 * (t * V);
  c = t * t - dis * dis;
  d = sqrt(b * b - 4 * a * c);
  t1 = (-b + d) / (2 * a);
  t2 = (-b - d) / (2 * a);
  if (t1 > t2) swap(t1, t2);
  if (t1 > 0) return t1;
  if (t2 > 0) return t2;
  return 1e10;
}
int main() {
  int R;
  scanf("%d %d %d %d %d %d %d", &O.x, &O.y, &O.z, &V.x, &V.y, &V.z, &R);
  double ans;
  ans = 1e9;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    point p, p2;
    int r, m;
    scanf("%d %d %d %d %d", &p.x, &p.y, &p.z, &r, &m);
    ans = min(ct(p, r + R), ans);
    for (int j = 0; j < m; j++) {
      scanf("%d %d %d", &p2.x, &p2.y, &p2.z);
      ans = min(ct(p + p2, R), ans);
    }
  }
  if (ans == 1e9)
    printf("-1\n");
  else
    printf("%.10lf\n", ans);
}
