#include <bits/stdc++.h>
using namespace std;
inline double sqr(double x) { return x * x; }
inline int dblc(double x) { return abs(x) < 1e12 ? x : x > 0 ? 1 : -1; }
struct Tpnt {
  double x, y, z;
  Tpnt(double _x = 0, double _y = 0, double _z = 0) { x = _x, y = _y, z = _z; }
  void init() { scanf("%lf%lf%lf", &x, &y, &z); }
  inline Tpnt operator+(const Tpnt &b) const {
    return Tpnt(x + b.x, y + b.y, z + b.z);
  }
  inline Tpnt operator-(const Tpnt &b) const {
    return Tpnt(x - b.x, y - b.y, z - b.z);
  }
  inline double operator%(const Tpnt &b) const {
    return x * b.x + y * b.y + z * b.z;
  }
} O, V;
double R;
namespace Ninit {
void init() { O.init(), V.init(), scanf("%lf", &R); }
}  // namespace Ninit
namespace Nsolve {
double ans;
double calc(Tpnt A, double r) {
  double Fc = 1e20, t;
  double a = V % V, b = -2 * (A % V), c = A % A - r * r,
         dlt = b * b - 4 * a * c;
  if (dlt < 0) return Fc;
  t = (-b - sqrt(dlt)) / (2 * a);
  if (t > 0) Fc = min(Fc, t);
  t = (-b + sqrt(dlt)) / (2 * a);
  if (t > 0) Fc = min(Fc, t);
  return Fc;
}
void solve() {
  int n, m;
  Tpnt A, P;
  double r;
  for (ans = 1e20, cin >> n; n; --n) {
    A.init(), A = A - O, scanf("%lf", &r);
    ans = min(ans, calc(A, R + r));
    for (cin >> m; m; --m) P.init(), ans = min(ans, calc(A + P, R));
  }
  ans > 1e10 ? printf("-1\n") : printf("%.8lf\n", ans);
}
}  // namespace Nsolve
int main() {
  Ninit::init();
  Nsolve::solve();
  return 0;
}
