#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
const double eps = 1e-10;
int sign(double x) {
  if (x < -eps) return -1;
  return x > eps;
}
struct point {
  double x, y, z;
  void read() { cin >> x >> y >> z; }
  point() {}
  point(double xx, double yy, double zz) : x(xx), y(yy), z(zz) {}
  point operator+(point &a) { return point(a.x + x, a.y + y, a.z + z); }
};
int n;
point A, V;
double R, T;
bool touch;
void update(point B, double r) {
  double a, b, c, del, t1, t2;
  a = (V.x) * (V.x) + (V.y) * (V.y) + (V.z) * (V.z);
  b = (A.x - B.x) * V.x * 2 + (A.y - B.y) * V.y * 2 + (A.z - B.z) * V.z * 2;
  c = (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y) +
      (A.z - B.z) * (A.z - B.z) - r * r;
  del = b * b - 4 * a * c;
  if (sign(del) == -1) return;
  t1 = (-b + sqrt(del)) / a / 2;
  t2 = (-b - sqrt(del)) / a / 2;
  if (t1 > eps) {
    if (!touch)
      T = t1, touch = true;
    else
      T = min(T, t1);
  }
  if (t2 > eps) {
    if (!touch)
      T = t2, touch = true;
    else
      T = min(T, t2);
  }
}
int main() {
  A.read();
  V.read();
  cin >> R;
  touch = false;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    double r;
    int m;
    point O;
    O.read();
    cin >> r >> m;
    update(O, R + r);
    for (int j = 1; j <= m; j++) {
      point v;
      v.read();
      update(O + v, R);
    }
  }
  if (!touch)
    puts("-1");
  else
    printf("%.9lf", T);
  return 0;
}
