#include <bits/stdc++.h>
using namespace std;
struct Tp {
  double x, y, z;
  Tp(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {}
  Tp operator*(const double B) const { return Tp(x * B, y * B, z * B); }
  Tp operator+(const Tp& B) const { return Tp(x + B.x, y + B.y, z + B.z); }
  Tp operator-(const Tp& B) const { return Tp(x - B.x, y - B.y, z - B.z); }
  double Module() const { return sqrt(x * x + y * y + z * z); }
  Tp Normal() const {
    double m = Module();
    return Tp(x / m, y / m, z / m);
  }
  double SqDist(const Tp& B) const {
    return (x - B.x) * (x - B.x) + (y - B.y) * (y - B.y) +
           (z - B.z) * (z - B.z);
  }
} s, v, a;
vector<Tp> S;
double R, r;
int n, k;
inline double sqr(double x) { return x * x; }
inline double FirstInRadius(Tp a, Tp b, Tp v, double R) {
  Tp ab = a - b;
  Tp v2 = v.Normal();
  double vm = (ab.x * v2.x + ab.y * v2.y + ab.z * v2.z);
  Tp nearest = (vm < 0) ? b : (b + v2 * vm);
  if (nearest.SqDist(a) > R * R) return 1e100;
  double left = 0, right = (b - nearest).Module() / v.Module(), center;
  for (int j = 0; j < 33; j++) {
    center = (left + right) / 2;
    if ((b + v * center).SqDist(a) > R * R)
      left = center;
    else
      right = center;
  }
  return (left + right) / 2;
}
double CalcMine(Tp c, double r, vector<Tp>& S) {
  double ret = FirstInRadius(c, s, v, r + R);
  for (int i = 0; i < S.size(); i++) {
    double left = 0, right = 1, c1, c2;
    for (int j = 0; j < 33; j++) {
      c1 = left + (right - left) / 3;
      c2 = right - (right - left) / 3;
      if (FirstInRadius(c + S[i] * c1, s, v, R) <
          FirstInRadius(c + S[i] * c2, s, v, R))
        right = c2;
      else
        left = c1;
    }
    ret = min(ret, FirstInRadius(c + S[i], s, v, R));
    ret = min(ret, FirstInRadius(c + S[i] * ((left + right) / 2), s, v, R));
  }
  return ret;
}
int main() {
  double ans = 2e100;
  cin >> s.x >> s.y >> s.z >> v.x >> v.y >> v.z >> R;
  cin >> n;
  for (int i = 0; i < n; i++) {
    S.clear();
    cin >> a.x >> a.y >> a.z >> r >> k;
    for (int j = 0; j < k; j++) {
      Tp sh;
      cin >> sh.x >> sh.y >> sh.z;
      S.push_back(sh);
    }
    ans = min(ans, CalcMine(a, r, S));
  }
  cout.precision(15);
  if (ans > 1e99)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
