1 import java.io.BufferedReader;
    2 import java.io.InputStreamReader;
    3 import java.util.Scanner;
    4 
    5 public class solution2
    6   {
    7 
    8     private static final int MAX_N = 16;
    9 
   10     private void work()
   11     {
   12 
   13       Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(
   14                                  System.in), 1 << 16));
   15       double[] sx = new double[MAX_N];
   16       double[] sy = new double[MAX_N];
   17       double[] vx = new double[MAX_N];
   18       double[] vy = new double[MAX_N];
   19       double Hx, Hy, Hv;
   20       int n, tc = 1;
   21       while (true)
   22         {
   23           n = sc.nextInt();
   24           if (n == 0)
   25             break;
   26           for (int i = 0; i < n; i++)
   27             {
   28               sx[i] = sc.nextInt();
   29               sy[i] = sc.nextInt();
   30               vx[i] = sc.nextInt();
   31               vy[i] = sc.nextInt();
   32             }
   33           Hx = sc.nextInt();
   34           Hy = sc.nextInt();
   35           Hv = sc.nextInt();
   36 
   37           int[] p = new int[n];
   38           for (int i = 0; i < n; i++)
   39             {
   40               p[i] = i;
   41             }
   42           double best = Double.POSITIVE_INFINITY;
   43           do
   44             {
   45               double t = 0;
   46               double hx = Hx;
   47               double hy = Hy;
   48               for (int i = 0; i < n; i++)
   49                 {
   50                   double next = getIntersectionTime(hx, hy, sx[p[i]] + t
   51                                                     * vx[p[i]], sy[p[i]] + t * vy[p[i]], vx[p[i]],
   52                                                     vy[p[i]], Hv) + 1;
   53                   t += next;
   54                   hx = sx[p[i]] + t * vx[p[i]];
   55                   hy = sy[p[i]] + t * vy[p[i]];
   56                 }
   57               t += Math.sqrt((hx - Hx) * (hx - Hx) + (hy - Hy) * (hy - Hy))
   58                    / Hv;
   59               if (t < best)
   60                 best = t;
   61             }
   62           while (nextPerm(p));
   63           long time = Math.round(Math.ceil(3600 * best - 1e-9));
   64           System.out.printf(
   65             "Case %d: %d hour(s) %d minute(s) %d second(s)\n", tc++,
   66             time / 3600, (time % 3600) / 60, time % 60);
   67         }
   68       System.out.close();
   69     }
   70 
   71     private double getIntersectionTime(double hx, double hy, double sx,
   72                                        double sy, double vx, double vy, double hv)
   73     {
   74       double dx = hx - sx;
   75       double dy = hy - sy;
   76       double A = hv * hv - vx * vx - vy * vy;
   77       double B = dx * vx + dy * vy;
   78       double C = -dx * dx - dy * dy;
   79       double D = Math.sqrt(B * B - A * C);
   80       double t = -B - D;
   81       if (t < -1e-10)
   82         t = -B + D;
   83       return t / A;
   84     }
   85 
   86     private boolean nextPerm(int[] a)
   87     {
   88       if (a.length <= 1)
   89         {
   90           return false;
   91         }
   92       int i = a.length - 1;
   93       while (a[i - 1] >= a[i])
   94         {
   95           i--;
   96           if (i == 0)
   97             {
   98               return false;
   99             }
  100         }
  101       int j = a.length;
  102       while (a[j - 1] <= a[i - 1])
  103         {
  104           j--;
  105           if (j == 0)
  106             {
  107               return false;
  108             }
  109         }
  110       int tmp = a[i - 1];
  111       a[i - 1] = a[j - 1];
  112       a[j - 1] = tmp;
  113       i++;
  114       j = a.length;
  115       while (i < j)
  116         {
  117           tmp = a[i - 1];
  118           a[i - 1] = a[j - 1];
  119           a[j - 1] = tmp;
  120           i++;
  121           j--;
  122         }
  123       return true;
  124     }
  125 
  126     public static void main(String[] args)
  127     {
  128       new solution2().work();
  129     }
  130 
  131   }
  132