#include <bits/stdc++.h>
using namespace std;
double vx, vy, vz;
double func(double x, double y, double z, double r) {
  double A = vx * vx + vy * vy + vz * vz;
  double B = -2.0 * (vx * x + vy * y + vz * z);
  double C = x * x + y * y + z * z - r * r;
  double D = B * B - 4.0 * A * C;
  if (D < -0.5) return 1.0E+18;
  D = sqrt(max(D, 0.0));
  double ans = (-B - D) / 2.0 / A;
  if (ans < 0.0) return 1.0E+18;
  return ans;
}
int main(void) {
  int N, M, i, j;
  double Ax, Ay, Az, R, Ox, Oy, Oz, r, dx, dy, dz;
  cin >> Ax >> Ay >> Az >> vx >> vy >> vz >> R;
  cin >> N;
  double ans = 1.0E+18;
  for ((i) = 0; (i) < (int)(N); (i)++) {
    cin >> Ox >> Oy >> Oz >> r;
    Ox -= Ax;
    Oy -= Ay;
    Oz -= Az;
    ans = min(ans, func(Ox, Oy, Oz, R + r));
    cin >> M;
    for ((j) = 0; (j) < (int)(M); (j)++) {
      cin >> dx >> dy >> dz;
      ans = min(ans, func(Ox + dx, Oy + dy, Oz + dz, R));
    }
  }
  if (ans > 1.0E+18 / 2.0)
    cout << -1 << endl;
  else
    printf("%.9f\n", ans);
  return 0;
}
