#include <bits/stdc++.h>
using namespace std;
const double inf = 1e20, eps = 1e-9, PI = acos(-1);
double sq(double first) { return first * first; }
struct P {
  double a[3];
  P() {}
  P(double first, double second, double z) {
    a[0] = first, a[1] = second, a[2] = z;
  }
  bool operator==(const P &p) const {
    for (int i = (0); i < (int)(3); i++)
      if (!(fabs((a[i]) - (p.a[i])) < eps)) return 0;
    return 1;
  }
  bool operator<(const P &p) const {
    for (int i = (0); i < (int)(3); i++)
      if (!(fabs((a[i]) - (p.a[i])) < eps)) return ((a[i]) < (p.a[i]) - eps);
    return 0;
  }
  P operator-(P p) {
    P res;
    for (int i = (0); i < (int)(3); i++) res.a[i] = a[i] - p.a[i];
    return res;
  }
  P operator+(P p) {
    P res;
    for (int i = (0); i < (int)(3); i++) res.a[i] = a[i] + p.a[i];
    return res;
  }
  P operator*(double k) {
    P res;
    for (int i = (0); i < (int)(3); i++) res.a[i] = a[i] * k;
    return res;
  }
  P operator^(P p) {
    P res;
    for (int i = (0); i < (int)(3); i++) {
      int j = (i + 1) % 3;
      int k = (i + 2) % 3;
      res.a[i] = (a[j] * p.a[k] - a[k] * p.a[j]);
    }
    return res;
  }
  double operator*(P p) {
    double res = 0;
    for (int i = (0); i < (int)(3); i++) res += a[i] * p.a[i];
    return res;
  }
  void out() {
    for (int i = (0); i < (int)(3); i++) printf(" %f ", a[i]);
    puts("");
  }
  double mag2() { return sq(a[0]) + sq(a[1]) + sq(a[2]); }
  double mag() { return sqrt(mag2()); }
  P nor() {
    double l = mag();
    if ((fabs((l) - (0)) < eps)) return *this;
    return *this * (1 / l);
  }
  P rot(P z, double t) {
    return *this * cos(t) + (z ^ *this) * sin(t) +
           z * (z * (*this)) * (1 - cos(t));
  }
  P rot(P z) { return z ^ (*this) + z * (z * (*this)); }
  double dist(P p) { return (*this - p).mag(); }
  void eat() {
    for (int i = (0); i < (int)(3); i++) scanf("%lf", &a[i]);
  }
};
double ans = 1e20;
bool f(P a, P o, double r1, double r2, P v, double &res) {
  double A = v.mag2();
  double B = 2 * ((a - o) * v);
  double C = (a - o).mag2() - (r1 + r2) * (r1 + r2);
  double D = B * B - 4 * A * C;
  if (((D) < (0) - eps)) return 0;
  if (((D) > (0) + eps)) D = sqrt(D);
  res = (-B - D) / (2 * A);
  return res > 0;
}
void upd(double first) { ans = min(ans, first); }
int main() {
  P A, V;
  double R;
  A.eat();
  V.eat();
  scanf("%lf", &R);
  int n;
  scanf("%d", &n);
  for (int i = (0); i < (int)(n); i++) {
    P cen, p;
    double r;
    int m;
    cen.eat();
    scanf("%lf%d", &r, &m);
    double res;
    if (f(A, cen, R, r, V, res)) {
      upd(res);
    }
    while (m--) {
      p.eat();
      if (f(A, cen, R, 0, V, res)) upd(res);
      if (f(A, cen + p, R, 0, V, res)) upd(res);
      P c = cen;
      P d = cen + p;
      P cd = d - c;
      P ca = c - A;
      double A1 = (V ^ cd).mag2();
      if ((fabs((A1) - (0)) < eps)) continue;
      double B = (V ^ cd).mag() * (ca ^ cd).mag();
      double C = (ca ^ cd).mag2();
      double D = B * B - 4 * A1 * C;
      if (((D) > (0) - eps)) {
        if (((D) > (0) + eps)) D = sqrt(D);
        double t1 = (-B + D) / (2 * A1);
        if (t1 > 0) {
          P Q = A + V * t1;
          double dot1 = (Q - c) * (d - c);
          double dot2 = (Q - d) * (c - d);
          if (((dot1) > (0) - eps) && ((dot2) > (0) - eps)) upd(res);
        }
      }
    }
  }
  if ((fabs((ans) - (1e20)) < eps))
    puts("-1");
  else
    printf("%.20f\n", ans);
  return 0;
}
