#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
const int maxm = 10 + 2;
const double eps = 1e-10;
struct point {
  double x, y, z;
  point() {}
  point(double x, double y, double z) : x(x), y(y), z(z) {}
} v;
struct circle {
  double x, y, z, r;
} A;
double ans = 1e15;
void work(point k, double r) {
  double a = (v.x * v.x) + (v.y * v.y) + (v.z * v.z);
  double b =
      2 * ((v.x * (A.x - k.x)) + (v.y * (A.y - k.y)) + (v.z * (A.z - k.z)));
  double c = (A.x - k.x) * (A.x - k.x) + (A.y - k.y) * (A.y - k.y) +
             (A.z - k.z) * (A.z - k.z) - r * r;
  double d = b * b - 4 * a * c;
  if (d < 0) return;
  double x1 = (-b + sqrt(d)) / 2.0 / a;
  double x2 = (-b - sqrt(d)) / 2.0 / a;
  if (x1 < 0 && x2 < 0) return;
  if (x1 > 0) ans = min(ans, x1);
  if (x2 > 0) ans = min(ans, x2);
  if (x1 * x2 < 0) ans = 0.0;
}
double x, y, z, r, xx, yy, zz;
int n, m;
int main() {
  scanf("%lf %lf %lf", &A.x, &A.y, &A.z);
  scanf("%lf %lf %lf %lf", &v.x, &v.y, &v.z, &A.r);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lf %lf %lf %lf %d", &x, &y, &z, &r, &m);
    work(point(x, y, z), r + A.r);
    for (int j = 0; j < m; j++) {
      scanf("%lf %lf %lf", &xx, &yy, &zz);
      work(point(x + xx, y + yy, z + zz), A.r);
    }
  }
  if (ans != 1e15)
    printf("%.7lf\n", ans);
  else
    printf("-1\n");
  return 0;
}
