#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
inline int fcmp(double a, double b) {
  if (fabs(a - b) < eps) return 0;
  return a < b ? -1 : 1;
}
struct point3 {
  double x, y, z;
  point3() {}
  point3(double a, double b, double c) : x(a), y(b), z(c) {}
  point3 operator+(const point3 &p) {
    return point3(x + p.x, y + p.y, z + p.z);
  }
  point3 operator-(const point3 &p) {
    return point3(x - p.x, y - p.y, z - p.z);
  }
  point3 operator*(const double d) { return point3(x * d, y * d, z * d); }
  point3 operator/(const double d) { return point3(x / d, y / d, z / d); }
  point3 operator&(const point3 &p) {
    return point3(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x);
  }
  long double operator^(const point3 &p) { return x * p.x + y * p.y + z * p.z; }
  double len() { return sqrt(x * x + y * y + z * z); }
  void in() { scanf("%lf%lf%lf", &x, &y, &z); }
};
double pToLine(point3 p, point3 a, point3 b) {
  return (p - a & b - a).len() / (a - b).len();
}
long double cald(point3 a, point3 u, point3 b, point3 v) {
  return ((u ^ v) * (v ^ a - b) - (v ^ v) * (u ^ a - b)) /
         ((u ^ u) * (v ^ v) - (u ^ v) * (u ^ v));
}
double lineToLineEx(point3 a, point3 b, point3 c, point3 d, point3 &A,
                    point3 &B) {
  point3 va = b - a, vc = d - c;
  A = a + va * cald(a, va, c, vc);
  B = c + vc * cald(c, vc, a, va);
  return (B - A).len();
}
double pToLineEx(point3 p, point3 a, point3 b, point3 &o) {
  point3 n = a - p & b - p;
  if (!fcmp(n.len(), 0)) {
    o = p;
    return 0;
  }
  point3 v = b - a & n;
  lineToLineEx(a, b, p, p + v, o, o);
  return (o - p).len();
}
point3 A, B, V;
double mins;
void update(const point3 &o, double l) {
  point3 p;
  double h = pToLineEx(o, A, B, p);
  if (fcmp(h, l) > 0 || (V ^ p - A) < 0) {
    return;
  }
  double tp = ((A - p).len() - sqrt(l * l - h * h)) / V.len();
  if (mins < 0 || tp < mins) mins = tp;
}
int main() {
  point3 o, p, l, r, mid;
  double r1, r2;
  int n, m, i;
  while (~scanf("%lf%lf%lf", &A.x, &A.y, &A.z)) {
    V.in();
    B = A + V;
    scanf("%lf%d", &r1, &n);
    mins = -1;
    while (n--) {
      o.in();
      scanf("%lf%d", &r2, &m);
      update(o, r1 + r2);
      for (i = 0; i < m; i++) {
        p.in();
        update(o + p, r1);
      }
    }
    printf("%.11f\n", mins);
  }
  return 0;
}
