#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& x) {
  bool fu = 0;
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') fu = 1, c = getchar();
  for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
  if (fu) x = -x;
};
template <class T>
inline void read(T& x, T& y) {
  read(x);
  read(y);
}
template <class T>
inline void read(T& x, T& y, T& z) {
  read(x);
  read(y);
  read(z);
}
inline char getc() {
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  return c;
}
struct node {
  double x, y, z;
};
node operator+(node a, node b) {
  return (node){a.x + b.x, a.y + b.y, a.z + b.z};
}
node operator-(node a, node b) {
  return (node){a.x - b.x, a.y - b.y, a.z - b.z};
}
node operator*(node a, double t) { return (node){a.x * t, a.y * t, a.z * t}; }
double mul(node a, node b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
int n, i, j, k, p;
double R, ro[110], m[110], l, r, t;
int g[110];
node A, V0, O[110], P[110][11];
void read(node& a) { scanf("%lf%lf%lf", &a.x, &a.y, &a.z); }
double sqrlen(node a) {
  return ((a.x) * (a.x)) + ((a.y) * (a.y)) + ((a.z) * (a.z));
}
double len(node a) { return sqrt(sqrlen(a)); }
double dis(node a, node b) { return len(a - b); }
double ddd(node p, node a, node v) {
  double t;
  t = mul(p - a, v) / sqrlen(v);
  if (t >= 0 && t <= 1) return dis(p, a + v * t);
  return min(dis(p, a), dis(p, a + v));
}
bool ok(double T) {
  int i, j;
  double a, b, c, d, e, f, p, q, t0, t1, xx, yy;
  node V = V0 * T;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= g[i]; j++) {
      double a1, b1, c1, a2, b2, c2, de, s, t, dd;
      a1 = sqrlen(V);
      b1 = -mul(V, P[i][j]);
      c1 = -mul(V, O[i] - A);
      a2 = b1;
      b2 = sqrlen(P[i][j]);
      c2 = -mul(P[i][j], A - O[i]);
      de = a1 * b2 - b1 * a2;
      s = (c1 * b2 - c2 * b1) / de;
      t = (a1 * c2 - a2 * c1) / de;
      if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
        dd = dis(A + V * s, O[i] + P[i][j] * t);
      else
        dd = min(min(ddd(A, O[i], P[i][j]), ddd(A + V, O[i], P[i][j])),
                 min(ddd(O[i], A, V), ddd(O[i] + P[i][j], A, V)));
      if (dd <= R + 1e-12) return 1;
    }
  return 0;
}
int main() {
  read(A);
  read(V0);
  cin >> R;
  read(n);
  for (i = 1; i <= n; i++) {
    read(O[i]), cin >> ro[i] >> g[i];
    for (j = 1; j <= g[i]; j++) read(P[i][j]);
  }
  l = 0, r = double(1e12);
  for (i = 1; i <= n; i++) {
    double a, b, c, p, q, t0, t1;
    a = b = c = 0;
    p = V0.x;
    q = A.x - O[i].x;
    a += p * p;
    b += 2 * p * q;
    c += q * q;
    p = V0.y;
    q = A.y - O[i].y;
    a += p * p;
    b += 2 * p * q;
    c += q * q;
    p = V0.z;
    q = A.z - O[i].z;
    a += p * p;
    b += 2 * p * q;
    c += q * q;
    c -= ((R + ro[i]) * (R + ro[i]));
    double de = b * b - 4 * a * c;
    if (de < 0) continue;
    t0 = (-b + sqrt(de)) / (2 * a);
    t1 = (-b - sqrt(de)) / (2 * a);
    if (t0 >= 0) r = min(r, t0);
    if (t1 >= 0) r = min(r, t1);
  }
  while (r - l >= 1e-7) {
    t = (l + r) / 2;
    if (ok(t))
      r = t;
    else
      l = t;
  }
  if (r > double(1e10))
    cout << -1 << endl;
  else
    cout << fixed << setprecision(10) << (l + r) / 2 << endl;
  return 0;
}
