#include <bits/stdc++.h>
using namespace std;
int testnum;
double ax, ay, az, bx, by, bz, R;
int n;
double ox[1000], oy[1000], oz[1000], rr[1000], m[1000];
double spkx[1000][100], spky[1000][100], spkz[1000][100];
pair<bool, double> solve(double a, double b, double c) {
  double det = b * b - 4 * a * c;
  if (det < 0) return make_pair(false, 0.0);
  det = sqrt(det);
  double r1 = (-b + det) / (a + a);
  double r2 = (-b - det) / (a + a);
  if (r1 < 0 && r2 < 0) return make_pair(false, 0.0);
  if (r1 < 0) return make_pair(true, r2);
  if (r2 < 0) return make_pair(true, r1);
  return make_pair(true, min(r1, r2));
}
pair<bool, double> bomb(double px, double py, double pz, double r) {
  double a = (bx * bx + by * by + bz * bz);
  double b = 2 * (ax * bx + ay * by + az * bz - px * (bx)-py * (by)-pz * (bz));
  double c = (px * px + py * py + pz * pz) + (ax * ax + ay * ay + az * az) -
             r * r - 2 * (px * ax + py * ay + pz * az);
  return solve(a, b, c);
}
void preprocess() {}
void solve() {
  bool hit = false;
  double mintime = 1e24;
  pair<bool, double> temp;
  for (int i = 0; i < n; i++) {
    temp = bomb(ox[i], oy[i], oz[i], rr[i] + R);
    if (temp.first) {
      hit = true;
      mintime = min(mintime, temp.second);
    }
    for (int j = 0; j < m[i]; j++) {
      temp =
          bomb(ox[i] + spkx[i][j], oy[i] + spky[i][j], oz[i] + spkz[i][j], R);
      if (temp.first) {
        hit = true;
        mintime = min(mintime, temp.second);
      }
    }
  }
  if (hit)
    printf("%.9lf\n", mintime);
  else
    printf("-1\n");
}
bool input() {
  scanf("%lf", &ax);
  scanf("%lf", &ay);
  scanf("%lf", &az);
  scanf("%lf", &bx);
  scanf("%lf", &by);
  scanf("%lf", &bz);
  scanf("%lf", &R);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lf", &ox[i]);
    scanf("%lf", &oy[i]);
    scanf("%lf", &oz[i]);
    scanf("%lf", &rr[i]);
    scanf("%lf", &m[i]);
    for (int j = 0; j < m[i]; j++) {
      scanf("%lf", &spkx[i][j]);
      scanf("%lf", &spky[i][j]);
      scanf("%lf", &spkz[i][j]);
    }
  }
  return true;
}
int main() {
  preprocess();
  int T = 1;
  for (testnum = 1; testnum <= T; testnum++) {
    if (!input()) break;
    solve();
  }
}
