#include <bits/stdc++.h>
using namespace std;
inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a < b ? a : b; }
inline double sqr(double x) { return x * x; }
inline int sqr(int x) { return x * x; }
struct point {
  double x, y, z;
  point() {}
  point(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {}
  point operator+(point b) { return point(x + b.x, y + b.y, z + b.z); }
  point operator-(point b) { return point(x - b.x, y - b.y, z - b.z); }
  double operator*(point b) { return (x * b.x + y * b.y + z * b.z); }
  double psqr() { return sqr(x) + sqr(y) + sqr(z); }
  double get() { return scanf("%lf %lf %lf", &x, &y, &z); }
};
point A, v;
vector<point> m, p[105];
inline double min(double a, double b) { return a < b ? a : b; }
inline void chkmin(double &a, double b) {
  if (a > b) a = b;
}
double getmin(point x, double dis) {
  double a(v.psqr()), b((v * (A - x)) * 2.0), c((A - x).psqr() - sqr(dis));
  double d(sqr(b) - ((a * c) * 4.0));
  if (d < -1e-7) return 0x3fffffff;
  d = sqrt(d);
  double x1((d - b) / (2.0 * a)), x2((-d - b) / (2.0 * a));
  if (x1 < 1e-7) x1 = 0x3fffffff;
  if (x2 < 1e-7) x2 = 0x3fffffff;
  return min(x1, x2);
}
int n;
double R;
int main() {
  while (A.get() == 3 && v.get() == 3 && scanf("%lf %d", &R, &n) == 2) {
    point tmp;
    double ans(0x3fffffff);
    for (int i(0); i < (n); ++i) {
      double r;
      int m;
      tmp.get();
      scanf("%lf %d", &r, &m);
      chkmin(ans, getmin(tmp, R + r));
      for (int j(0); j < (m); ++j) {
        point p;
        p.get();
        chkmin(ans, getmin(tmp + p, R));
      }
    }
    if (ans >= 0x3fffffff)
      puts("-1");
    else
      printf("%lf\n", ans);
  }
  return 0;
}
