#include <bits/stdc++.h>
using namespace std;
struct Point {
  double x, y, z;
  Point() {}
  Point(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {}
  double sqr() { return x * x + y * y + z * z; }
  friend Point operator+(Point x, Point y) {
    return Point(x.x + y.x, x.y + y.y, x.z + y.z);
  }
  friend Point operator-(Point x, Point y) {
    return Point(x.x - y.x, x.y - y.y, x.z - y.z);
  }
} zCenter, v;
double R;
double dot(Point x, Point y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
double ans = 1e10;
void check(Point p, double r) {
  p = zCenter - p;
  double a = v.sqr();
  double b = 2 * dot(p, v);
  double c = p.sqr() - r * r;
  double delta = b * b - 4 * a * c;
  if (delta < 0) return;
  double x1 = (-b + sqrt(delta)) / 2 / a;
  double x2 = (-b - sqrt(delta)) / 2 / a;
  if (x1 >= 0) ans = min(ans, x1);
  if (x2 >= 0) ans = min(ans, x2);
}
int main() {
  int n;
  scanf("%lf%lf%lf%lf%lf%lf%lf", &zCenter.x, &zCenter.y, &zCenter.z, &v.x, &v.y,
        &v.z, &R);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    Point o;
    double r;
    int cnt;
    scanf("%lf%lf%lf%lf%d", &o.x, &o.y, &o.z, &r, &cnt);
    check(o, r + R);
    while (cnt--) {
      Point p;
      scanf("%lf%lf%lf", &p.x, &p.y, &p.z);
      check(o + p, R);
    }
  }
  if (ans > 1e9)
    puts("-1");
  else
    printf("%.10f\n", ans);
  return 0;
}
