#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
const int maxk = 100000;
int a[3], v[3], o[3], p[3], R, n, r, m;
double t = 1e20, A, B, C, D;
void check(int c[3], int Rr) {
  double t1, t2;
  B = C = D = 0;
  for (int k = 0, _n = (3); k < _n; k++) {
    B += 2 * v[k] * (a[k] - c[k]);
    C += (a[k] - c[k]) * (a[k] - c[k]);
  }
  C -= Rr * Rr;
  D = B * B - 4 * A * C;
  if (D < 0) return;
  t1 = (-B + sqrt(D)) / (2 * A);
  t2 = (-B - sqrt(D)) / (2 * A);
  if (t1 > 0 && t1 < t) t = t1;
  if (t2 > 0 && t2 < t) t = t2;
}
int main() {
  scanf("%d%d%d%d%d%d%d", &a[0], &a[1], &a[2], &v[0], &v[1], &v[2], &R);
  for (int k = 0, _n = (3); k < _n; k++) A += v[k] * v[k];
  scanf("%d", &n);
  for (int i = 0, _n = (n); i < _n; i++) {
    scanf("%d%d%d%d%d", &o[0], &o[1], &o[2], &r, &m);
    check(o, r + R);
    for (int j = 0, _n = (m); j < _n; j++) {
      scanf("%d%d%d", &p[0], &p[1], &p[2]);
      for (int k = 0, _n = (3); k < _n; k++) p[k] += o[k];
      check(p, R);
    }
  }
  if (t > 1e18) t = -1;
  printf("%.10lf\n", t);
  return 0;
}
