#include <bits/stdc++.h>
using namespace std;
double A[3], v[3], R;
int n;
bool in(double radis, double *pos) {
  double dis2 = (pos[0] - A[0]) * (pos[0] - A[0]) +
                (pos[1] - A[1]) * (pos[1] - A[1]) +
                (pos[2] - A[2]) * (pos[2] - A[2]);
  if (dis2 < radis * radis) return 1;
  return 0;
}
double solve(double radis, double *pos) {
  double a = 0, b = 0, c = 0;
  for (int i = 0; i < 3; ++i)
    a += v[i] * v[i], b += 2 * v[i] * (A[i] - pos[i]),
        c += (A[i] - pos[i]) * (A[i] - pos[i]);
  c -= radis * radis;
  double delta = b * b - 4 * a * c;
  if (delta >= 0) {
    double t0 = (-b + sqrt(delta)) / (2 * a);
    double t1 = (-b - sqrt(delta)) / (2 * a);
    if (t0 > t1) swap(t0, t1);
    if (t0 > 0) return t0;
    if (t1 > 0) return t1;
    return -1;
  }
  return -1;
}
int main() {
  double ans = 1e15;
  for (int i = 0; i < 3; ++i) cin >> A[i];
  for (int i = 0; i < 3; ++i) cin >> v[i];
  cin >> R;
  int n;
  cin >> n;
  bool flag = 0;
  double x;
  while (n--) {
    double p[3];
    for (int i = 0; i < 3; ++i) cin >> p[i];
    double r;
    int m;
    cin >> r >> m;
    double a[3];
    if (-1 != (x = solve(R + r, p))) {
      flag = 1;
      ans = min(ans, x);
    }
    for (int i = 1; i <= m; ++i) {
      for (int i = 0; i < 3; ++i) cin >> a[i], a[i] += p[i];
      if (-1 != (x = solve(R, a))) {
        flag = 1;
        ans = min(ans, x);
      }
    }
  }
  if (flag) {
    printf("%.7lf", ans);
  } else
    puts("-1");
}
