#include <bits/stdc++.h>
using namespace std;
class vec {
 public:
  long double x, y, z;
  vec operator-(const vec& rhs) {
    vec res;
    res.x = x - rhs.x;
    res.y = y - rhs.y;
    res.z = z - rhs.z;
    return res;
  }
  vec operator+(const vec& rhs) {
    vec res;
    res.x = x + rhs.x;
    res.y = y + rhs.y;
    res.z = z + rhs.z;
    return res;
  }
  vec operator*(long double t) {
    vec res = *this;
    res.x *= t;
    res.y *= t;
    res.z *= t;
    return res;
  }
};
long double len(const vec& v) {
  return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
long double len2(const vec& v) { return v.x * v.x + v.y * v.y + v.z * v.z; }
long double dot(const vec& a, const vec& b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}
long double cross(const vec& a, const vec& b) {
  vec r;
  r.x = a.y * b.z - b.y * a.z;
  r.y = a.z * b.x - b.z * a.x;
  r.z = a.x * b.y - b.x * a.y;
  return len(r);
}
istream& operator>>(istream& s, vec& v) {
  s >> v.x >> v.y >> v.z;
  return s;
}
ostream& operator<<(ostream& s, vec& v) {
  s << "[" << v.x << ", " << v.y << ", " << v.z << "]";
  return s;
}
long double calc_t(vec p, vec v, long double R) {
  if (dot(p, v) < 0) return 1E+100;
  long double t = dot(p, v) / len2(v);
  if (len2(v * t - p) > R * R) return 1E+100;
  long double l = 0;
  long double r = t;
  while (r - l > 1E-10) {
    t = (r + l) / 2;
    if (len2(v * t - p) > R * R)
      l = t;
    else
      r = t;
  }
  vec x = (v * ((r + l) / 2) - p);
  return (r + l) / 2;
}
int main() {
  vec A, v;
  long double R;
  cin >> A >> v >> R;
  int N;
  cin >> N;
  long double res = 1E+100;
  for (int i = 0; i < N; i++) {
    int m;
    long double r;
    vec C;
    cin >> C >> r >> m;
    res = min(res, calc_t(C - A, v, R + r));
    for (int j = 0; j < m; j++) {
      vec p;
      cin >> p;
      res = min(res, calc_t(C + p - A, v, R));
    }
  }
  if (res == 1E+100)
    cout << -1 << endl;
  else
    cout << fixed << setprecision(10) << res << endl;
}
