#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
template <class T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
struct point {
  double x, y, z;
};
point operator+(point a, point b) {
  a.x += b.x;
  a.y += b.y;
  a.z += b.z;
  return a;
}
point operator-(point a, point b) {
  a.x -= b.x;
  a.y -= b.y;
  a.z -= b.z;
  return a;
}
point operator*(point a, double b) {
  a.x *= b;
  a.y *= b;
  a.z *= b;
  return a;
}
point operator/(point a, double b) {
  a.x /= b;
  a.y /= b;
  a.z /= b;
  return a;
}
double operator*(point a, point b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
point operator^(point a, point b) {
  point c;
  c.x = a.y * b.z - a.z * b.y;
  c.y = a.z * b.x - a.x * b.z;
  c.z = a.x * b.y - a.y * b.x;
  return c;
}
point A, v, O[100], p[100][100];
double R, r[100];
int n, m[100];
double tmin(point A, point O, point v, double R) {
  double t = (v * (A - O)) / (((v) * (v)));
  t = -t;
  if (t >= 0.0) {
    double rmin = (((A - O) + (v * t)) * ((A - O) + (v * t)));
    if (rmin < ((R) * (R)) + eps) {
      return (-(v * (A - O)) -
              sqrt(abs(((v * (A - O)) * (v * (A - O))) -
                       ((v) * (v)) * (((A - O) * (A - O)) - ((R) * (R)))))) /
             ((v) * (v));
    } else
      return 1e20;
  }
  return 1e20;
}
int main() {
  cin >> A.x >> A.y >> A.z >> v.x >> v.y >> v.z >> R;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> O[i].x >> O[i].y >> O[i].z >> r[i] >> m[i];
    for (int j = 0; j < m[i]; j++) cin >> p[i][j].x >> p[i][j].y >> p[i][j].z;
  }
  double ans = 1e20;
  for (int i = 0; i < n; i++) {
    ans = min(ans, tmin(A, O[i], v, R + r[i]));
    for (int j = 0; j < m[i]; j++) {
      ans = min(ans, tmin(A, O[i] + p[i][j], v, R));
    }
  }
  if (ans > 1e19)
    printf("-1\n");
  else
    printf("%.10lf\n", ans);
  return 0;
}
