#include <bits/stdc++.h>
using namespace std;
struct Point;
double Distance(const Point& p1, const Point& p2);
struct Point {
  double x_, y_, z_;
  Point(double x, double y, double z) {
    x_ = x;
    y_ = y;
    z_ = z;
  }
  Point(const Point& p) {
    x_ = p.x_;
    y_ = p.y_;
    z_ = p.z_;
  }
  Point() { x_ = y_ = z_ = 0.0; }
  Point(const Point& p, const Point& tambah, double mult) {
    x_ = p.x_ + tambah.x_ * mult;
    y_ = p.y_ + tambah.y_ * mult;
    z_ = p.z_ + tambah.z_ * mult;
  }
  void normalize() {
    double length = Distance(Point(), *this);
    x_ /= length;
    y_ /= length;
    z_ /= length;
  }
};
double Distance(const Point& p1, const Point& p2) {
  double dx = p1.x_ - p2.x_;
  double dy = p1.y_ - p2.y_;
  double dz = p1.z_ - p2.z_;
  return sqrt(dx * dx + dy * dy + dz * dz);
}
int negative;
double DistanceToLine(const Point& a, const Point& b, const Point& x,
                      Point* out_point) {
  Point u(b.x_ - a.x_, b.y_ - a.y_, b.z_ - a.z_);
  Point v(x.x_ - a.x_, x.y_ - a.y_, x.z_ - a.z_);
  u.normalize();
  negative = 0;
  double dotprod = u.x_ * v.x_ + u.y_ * v.y_ + u.z_ * v.z_;
  if (dotprod + 1e-9 < 0.0) negative = 1;
  out_point->x_ = a.x_ + u.x_ * dotprod;
  out_point->y_ = a.y_ + u.y_ * dotprod;
  out_point->z_ = a.z_ + u.z_ * dotprod;
  return Distance(*out_point, x);
}
int main() {
  double cx, cy, cz;
  double vx, vy, vz;
  double initradi;
  cin >> cx >> cy >> cz >> vx >> vy >> vz >> initradi;
  Point bola(cx, cy, cz);
  Point arah(vx, vy, vz);
  Point bola2(cx + vx, cy + vy, cz + vz);
  double ret = 1000000000.0;
  vector<pair<Point, double> > circles;
  int n;
  cin >> n;
  for (int(i) = 0; (i) < (n); ++(i)) {
    double ox, oy, oz;
    double radi;
    int spikes;
    cin >> ox >> oy >> oz >> radi >> spikes;
    circles.push_back(make_pair(Point(ox, oy, oz), radi));
    for (int(j) = 0; (j) < (spikes); ++(j)) {
      double px, py, pz;
      cin >> px >> py >> pz;
      circles.push_back(make_pair(Point(ox + px, oy + py, oz + pz), 0.0));
    }
  }
  for (int(i) = 0; (i) < (((int)circles.size())); ++(i)) {
    Point ctr = circles[i].first;
    double rad = circles[i].second + initradi;
    Point intersect;
    double dist = DistanceToLine(bola, bola2, ctr, &intersect);
    if (negative) continue;
    if (dist > rad + 1e-9) continue;
    double remdist = sqrt(rad * rad - dist * dist);
    double totaldist = Distance(intersect, bola);
    totaldist -= remdist;
    ret = min((ret), (totaldist / sqrt(vx * vx + vy * vy + vz * vz)));
  }
  if (ret >= 999999999.0) {
    cout << -1 << endl;
  } else {
    printf("%.10lf\n", ret);
  }
  return 0;
}
