#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
const long double INF = 1e18;
long double sqr(long double x) { return x * x; }
struct Vec {
  long double x, y, z;
  Vec(long double _x, long double _y, long double _z) : x(_x), y(_y), z(_z) {}
  Vec() {}
  long double norm() { return sqrt(sqr(x) + sqr(y) + sqr(z)); }
};
Vec operator+(Vec a, Vec b) { return Vec(a.x + b.x, a.y + b.y, a.z + b.z); }
Vec operator-(Vec a, Vec b) { return Vec(a.x - b.x, a.y - b.y, a.z - b.z); }
Vec operator*(Vec a, long double alpha) {
  return Vec(a.x * alpha, a.y * alpha, a.z * alpha);
}
long double scalProd(Vec a, Vec b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
struct Mine {
  Vec o;
  long double rad;
  Mine(Vec _o, long double _rad) : o(_o), rad(_rad) {}
};
istream& operator>>(istream& istr, Vec& v) {
  istr >> v.x >> v.y >> v.z;
  return istr;
}
void solve() {
  Vec r0, v;
  long double rad;
  cin >> r0 >> v >> rad;
  int n;
  cin >> n;
  vector<Mine> mines;
  for (int i = 0; i < n; i++) {
    Vec o;
    long double m_rad;
    int m;
    cin >> o >> m_rad >> m;
    mines.push_back(Mine(o, m_rad));
    for (int j = 0; j < m; j++) {
      Vec p;
      cin >> p;
      mines.push_back(Mine(o + p, 0));
    }
  }
  long double ans = INF;
  for (int i = 0; i < mines.size(); i++) {
    long double t0 = scalProd(mines[i].o - r0, v) / sqr(v.norm());
    Vec p0 = r0 + v * t0;
    long double h = sqr(rad + mines[i].rad) - sqr((mines[i].o - p0).norm());
    if (h < -EPS) continue;
    if (h < 0) h = 0;
    h = sqrt(h);
    long double th = h / v.norm();
    if (t0 - th > EPS) ans = min(ans, t0 - th);
  }
  if (ans < 1e9)
    cout << fixed << setprecision(9) << ans << '\n';
  else
    cout << "-1\n";
}
int main() {
  solve();
  return 0;
}
