#include <bits/stdc++.h>
using namespace std;
struct nodd {
  nodd() {}
  nodd(double x, double y, double z) : x(x), y(y), z(z) {}
  double x, y, z;
};
struct node {
  double x, y, z, r;
};
node Q;
nodd v;
double ans = 0x3f3f3f3f;
void work(nodd k, double r) {
  double a = (v.x * v.x) + (v.y * v.y) + (v.z * v.z);
  double b =
      2 * ((v.x * (Q.x - k.x)) + (v.y * (Q.y - k.y)) + (v.z * (Q.z - k.z)));
  double c = (Q.x - k.x) * (Q.x - k.x) + (Q.y - k.y) * (Q.y - k.y) +
             (Q.z - k.z) * (Q.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;
}
void init() {
  scanf("%lf%lf%lf%lf%lf%lf", &Q.x, &Q.y, &Q.z, &v.x, &v.y, &v.z);
  scanf("%lf", &Q.r);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    double bax, bay, baz, R, x, y, r, z;
    int m;
    scanf("%lf%lf%lf%lf%d", &x, &y, &z, &r, &m);
    work(nodd(x, y, z), r + Q.r);
    for (int j = 1; j <= m; j++) {
      double xx, yy, zz;
      scanf("%lf%lf%lf", &xx, &yy, &zz);
      work(nodd(xx + x, yy + y, zz + z), Q.r);
    }
  }
  if (ans == 0x3f3f3f3f)
    printf("-1\n");
  else
    printf("%.8lf\n", ans);
}
int main() {
  init();
  return 0;
}
