#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
const double INF = 1e+18, EPS = 1e-10;
double Ax, Ay, Az, vx, vy, vz, R;
int n, m;
double CC = INF;
double sqr(double x) { return x * x; }
void calc(double x, double y, double z, double r) {
  x = Ax - x, y = Ay - y, z = Az - z;
  r += R;
  double A = sqr(vx) + sqr(vy) + sqr(vz), B = (x * vx + y * vy + z * vz) * 2.0,
         C = sqr(x) + sqr(y) + sqr(z) - sqr(r), delta = sqr(B) - 4.0 * A * C;
  if (delta < 0) return;
  delta = sqrt(delta);
  double x1 = (-B + delta) / 2 / A, x2 = (-B - delta) / 2 / A;
  if (x1 >= 0) CC = min(CC, x1);
  if (x2 >= 0) CC = min(CC, x2);
}
int main() {
  cin >> Ax >> Ay >> Az >> vx >> vy >> vz >> R >> n;
  for (int i = 1; i <= n; ++i) {
    double x0, y0, z0, r0;
    cin >> x0 >> y0 >> z0 >> r0 >> m;
    calc(x0, y0, z0, r0);
    for (int i = 1; i <= m; ++i) {
      double dx, dy, dz;
      cin >> dx >> dy >> dz;
      calc(x0 + dx, y0 + dy, z0 + dz, 0);
    }
  }
  if (CC != INF)
    printf("%.10lf\n", CC);
  else
    puts("-1");
  fclose(stdin);
  fclose(stdout);
  return 0;
}
