#include <bits/stdc++.h>
using namespace std;
inline int IN() {
  char ch;
  (ch = getchar());
  int f = 0, x = 0;
  for (; ((ch) == '\n' || (ch) == '\r' || (ch) == '\t' || (ch) == ' ');
       (ch = getchar()))
    ;
  if (ch == '-') f = 1, (ch = getchar());
  for (; !((ch) == '\n' || (ch) == '\r' || (ch) == '\t' || (ch) == ' ');
       (ch = getchar()))
    x = x * 10 + ch - '0';
  return (f) ? (-x) : (x);
}
double R, r;
int n;
struct po {
  double x, y, z;
  void read() { scanf("%lf%lf%lf", &x, &y, &z); }
  po operator+(const po &a) const { return (po){x + a.x, y + a.y, z + a.z}; }
  po operator-(const po &a) const { return (po){x - a.x, y - a.y, z - a.z}; }
  double R() { return ((x) * (x)) + ((y) * (y)) + ((z) * (z)); }
  double operator^(const po &a) const { return x * a.x + y * a.y + z * a.z; }
} A, v, B, C;
double equ(double A, double B, double C) {
  double delta = (B * B) - 4 * A * C;
  if (delta < 0) return 1e100;
  delta = sqrt(delta);
  double x0 = (-B - delta) / (2 * A), x1 = (-B + delta) / (2 * A);
  if (x1 < 0) return 1e100;
  if (x0 < 0)
    return x1;
  else
    return x0;
}
double work(po O, double R) {
  O = O - A;
  return equ(v.R(), -2 * (v ^ O), O.R() - R * R);
}
double ans = 1e100;
int main() {
  A.read();
  v.read();
  R = IN();
  for (n = IN(); n; n--) {
    B.read();
    r = IN();
    int m = IN();
    ans = min(ans, work(B, r + R));
    while (m--) {
      C.read();
      C = C + B;
      ans = min(ans, work(C, R));
    }
  }
  if (ans > 1e19)
    puts("-1");
  else
    printf("%.20lf\n", ans);
  return 0;
}
