#include <bits/stdc++.h>
using namespace std;
struct point {
  double x, y, z;
  point(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {}
};
struct sphere : point {
  double r;
  sphere() {}
};
point v[105][15];
sphere sp[105];
int cnt[105];
sphere sp0;
point v0;
int n;
int fcmp(double x) {
  if ((x > 0 ? x : -(x)) < 1e-7) return 0;
  return x > 0 ? 1 : -1;
}
double sol(double a, double b, double c) {
  if (fcmp(-b - sqrt((((b) * (b)) - 4 * a * c))) >= 0)
    return (-b - sqrt((((b) * (b)) - 4 * a * c))) / (a * 2);
  return (-b + sqrt((((b) * (b)) - 4 * a * c))) / (a * 2);
}
double work() {
  int i, j, flag = 0;
  double t = 0x7ffffff, a, b, c;
  a = ((v0.x) * (v0.x)) + ((v0.y) * (v0.y)) + ((v0.z) * (v0.z));
  for (i = 1; i <= n; ++i) {
    b = 2 * v0.x * (sp0.x - sp[i].x) + 2 * v0.y * (sp0.y - sp[i].y) +
        2 * v0.z * (sp0.z - sp[i].z);
    c = ((sp0.x - sp[i].x) * (sp0.x - sp[i].x)) +
        ((sp0.y - sp[i].y) * (sp0.y - sp[i].y)) +
        ((sp0.z - sp[i].z) * (sp0.z - sp[i].z)) -
        ((sp0.r + sp[i].r) * (sp0.r + sp[i].r));
    if ((fcmp((((b) * (b)) - 4 * a * c)) >= 0 &&
         (fcmp(-b + sqrt((((b) * (b)) - 4 * a * c))) >= 0))) {
      t = min(t, sol(a, b, c));
      flag = 1;
    }
    for (j = 1; j <= cnt[i]; ++j) {
      b = 2 * v0.x * (sp0.x - v[i][j].x) + 2 * v0.y * (sp0.y - v[i][j].y) +
          2 * v0.z * (sp0.z - v[i][j].z);
      c = ((sp0.x - v[i][j].x) * (sp0.x - v[i][j].x)) +
          ((sp0.y - v[i][j].y) * (sp0.y - v[i][j].y)) +
          ((sp0.z - v[i][j].z) * (sp0.z - v[i][j].z)) - ((sp0.r) * (sp0.r));
      if ((fcmp((((b) * (b)) - 4 * a * c)) >= 0 &&
           (fcmp(-b + sqrt((((b) * (b)) - 4 * a * c))) >= 0))) {
        t = min(t, sol(a, b, c));
        flag = 1;
      }
    }
  }
  if (flag == 0) {
    printf("-1\n");
    exit(0);
  }
  return t;
}
int main() {
  int i, j;
  scanf("%lf%lf%lf%lf%lf%lf%lf", &sp0.x, &sp0.y, &sp0.z, &v0.x, &v0.y, &v0.z,
        &sp0.r);
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%lf%lf%lf%lf", &sp[i].x, &sp[i].y, &sp[i].z, &sp[i].r);
    scanf("%d", &cnt[i]);
    for (j = 1; j <= cnt[i]; ++j) {
      scanf("%lf%lf%lf", &v[i][j].x, &v[i][j].y, &v[i][j].z);
      v[i][j].x += sp[i].x;
      v[i][j].y += sp[i].y;
      v[i][j].z += sp[i].z;
    }
  }
  printf("%lf\n", work());
  return 0;
}
