#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65777216")
using namespace std;
int ax, ay, az;
int vx, vy, vz;
int R;
int n;
int x, y, z, r, m;
int px;
int py;
int pz;
double t = 1e100;
double solve(long long x, long long y, long long z, long long r) {
  double A = vx * vx + vy * vy + vz * vz;
  double B = -2 * vx * x - 2 * vy * y - 2 * vz * z;
  double C = x * x + y * y + z * z - (R + r) * (R + r);
  double D = B * B - 4 * A * C;
  if (D < 0) return 1e100;
  D = sqrt(D);
  double t1 = (-B - D) / 2 / A;
  double t2 = (-B + D) / 2 / A;
  double res = 1e100;
  if (t1 >= 0) res = min(res, t1);
  if (t2 >= 0) res = min(res, t2);
  return res;
}
int main() {
  cin >> ax >> ay >> az >> vx >> vy >> vz >> R;
  cin >> n;
  for (int i(0); i < (n); i++) {
    cin >> x >> y >> z >> r >> m;
    x -= ax;
    y -= ay;
    z -= az;
    t = min(t, solve(x, y, z, r));
    for (int j(0); j < (m); j++) {
      cin >> px >> py >> pz;
      t = min(t, solve(x + px, y + py, z + pz, 0));
    }
  }
  if (t > 1e50)
    puts("-1");
  else
    printf("%.10lf\n", t);
  return 0;
}
