#include <bits/stdc++.h>
using namespace std;
using namespace rel_ops;
const double PI = acos((double)-1);
int ts, ts2, ts3, ts4;
int n, m;
long long gcd(long long x, long long y) {
  long long t;
  for (; y != 0;) {
    t = x % y;
    x = y;
    y = t;
  }
  return x;
}
double sqr(double x) { return x * x; }
double ans = 1E14;
double stx, sty, stz, deathr, vx, vy, vz;
void update(double x) {
  if (x >= -1E-10) ans = min(ans, x);
}
void can(double x1, double y1, double z1, double r1) {
  double u1, u2, u3, u4, u5, u6, u7, u8, u9;
  double nwx, nwy, nwz, nwr;
  nwx = stx - x1;
  nwy = sty - y1;
  nwz = stz - z1;
  nwr = r1 + deathr;
  u3 = sqr(vx) + sqr(vy) + sqr(vz);
  u4 = 2 * (nwx * vx + nwy * vy + nwz * vz);
  u5 = sqr(nwx) + sqr(nwy) + sqr(nwz) - sqr(nwr);
  u6 = u4 * u4 - 4 * u3 * u5;
  if (u6 < -1E-10) return;
  u6 = max(u6, 0.);
  u7 = (-u4 + sqrt(u6)) / (2 * u3), u8 = (-u4 - sqrt(u6)) / (2 * u3);
  update(u7);
  update(u8);
}
int main() {
  int i, j, k, l, t1, t2, t3, t4, t5, t6, t7, t8, t9, t, nw;
  double nwx, nwy, nwz, nwr, tx, ty, tz;
  int tt1, tt2, tt3, tt4;
  double u1, u2, u3, u4, u5, u6, u7, u8, u9;
  char c1, c2, c3;
  ios::sync_with_stdio(0);
  srand((unsigned)time(0));
  cin >> stx >> sty >> stz >> vx >> vy >> vz >> deathr;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> nwx >> nwy >> nwz >> nwr >> m;
    can(nwx, nwy, nwz, nwr);
    for (j = 1; j <= m; j++) {
      cin >> tx >> ty >> tz;
      can(nwx + tx, nwy + ty, nwz + tz, 0.);
    }
  }
  if (ans == 1E14)
    printf("-1\n");
  else
    printf("%.10lf\n", max(0., ans));
  return 0;
}
