#include <bits/stdc++.h>
using namespace std;
struct point {
  double x, y, z, R;
};
point p;
point A, v;
point pp;
double ans;
int n, m;
double cal2(double num) {
  point p1;
  p1.x = A.x + num * v.x;
  p1.y = A.y + num * v.y;
  p1.z = A.z + num * v.z;
  double x = p1.x - pp.x;
  double y = p1.y - pp.y;
  double z = p1.z - pp.z;
  return x * x + y * y + z * z;
}
double cal(double num) {
  point p1;
  p1.x = A.x + num * v.x;
  p1.y = A.y + num * v.y;
  p1.z = A.z + num * v.z;
  double x = p1.x - p.x;
  double y = p1.y - p.y;
  double z = p1.z - p.z;
  return x * x + y * y + z * z;
}
void solve1() {
  double left = 0.0, right = 1.0e15;
  double mid, midmid, m1, m2;
  while (fabs(right - left) > 1.0e-10) {
    mid = (left + right) / 2;
    midmid = (mid + right) / 2;
    m1 = cal(mid);
    m2 = cal(midmid);
    if (m1 < m2)
      right = midmid;
    else
      left = mid;
  }
  double re = (A.R + p.R) * (A.R + p.R);
  if (m1 <= re) {
    left = 0;
    right = mid;
    mid = 0;
    while (fabs(right - left) > 1.0e-10) {
      mid = (left + right) / 2;
      midmid = (mid + right) / 2;
      m1 = cal(mid);
      m2 = cal(midmid);
      if (fabs(m1 - re) < fabs(m2 - re))
        right = midmid;
      else
        left = mid;
    }
    if (mid < ans) ans = mid;
  }
}
void solve2() {
  double left = 0.0, right = 1.0e15;
  double mid, midmid, m1, m2;
  while (fabs(right - left) > 1.0e-10) {
    mid = (left + right) / 2;
    midmid = (mid + right) / 2;
    m1 = cal2(mid);
    m2 = cal2(midmid);
    if (m1 < m2)
      right = midmid;
    else
      left = mid;
  }
  double re = A.R * A.R;
  if (m1 <= re) {
    left = 0;
    right = mid;
    mid = 0;
    while (fabs(right - left) > 1.0e-10) {
      mid = (left + right) / 2;
      midmid = (mid + right) / 2;
      m1 = cal2(mid);
      m2 = cal2(midmid);
      if (fabs(m1 - re) < fabs(m2 - re))
        right = midmid;
      else
        left = mid;
    }
    if (mid < ans) ans = mid;
  }
}
int main() {
  int i, j, k;
  while (scanf("%lf%lf%lf", &A.x, &A.y, &A.z) != EOF) {
    ans = 1.0e15;
    scanf("%lf%lf%lf%lf", &v.x, &v.y, &v.z, &A.R);
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%lf%lf%lf%lf%d", &p.x, &p.y, &p.z, &p.R, &m);
      solve1();
      while (m--) {
        scanf("%lf%lf%lf", &pp.x, &pp.y, &pp.z);
        pp.x += p.x;
        pp.y += p.y;
        pp.z += p.z;
        solve2();
      }
    }
    if (ans == 1.0e15)
      printf("-1\n");
    else
      printf("%.9lf\n", ans);
  }
  return 0;
}
