/* Problem 6--House of Mirrors
   You have to be good with trigonometry to do this one.  This solution
   emulates the beam of light.  At every step it computes the closest
   mirror that the light could hit, and then reflects the beam off that
   mirror.  This solution also uses Gaussian Elimination to row-reduce
   a matrix.  This is a good way to solve linear equations when you
   don't know for sure that there will even be a solution. */

import java.io.*;
import java.util.*;
import java.text.*;

class MT { /* holds mirror information */
 public double leftx, lefty, rightx, righty;
}

public class prob6 {

 public static BufferedReader in;
 public static PrintStream out;
 public static StringTokenizer st = new StringTokenizer ("");
 public static MT[] Mirrors = new MT[10]; /* Array of mirrors */
 public static int sz, ct;
     /*sz is the number of mirrors; ct is the number of bounces*/
 public static double sx, sy, sd;
     /* (sx,sy) is the current light origin; sd is dir */
 public static DecimalFormat df = new DecimalFormat ();

 public static void main (String[] args) throws Exception {

  int cs=0;
  df.setMinimumFractionDigits (2);
  df.setMaximumFractionDigits (2);
  in = new BufferedReader (new FileReader ("prob6.in"));
  out = new PrintStream (new FileOutputStream ("prob6.out"));
  while (Read ()) { /* Read in data */
   while (Process ()); /*Bounce beam off mirrors until it doesn't hit */
    out.print ("Case "+(++cs)+":  "); /* any more mirrors. */
    if (ct==0) {
     out.println ("The beam is not reflected.");
     out.println ();
    } else { /* Depending on how many bounces, print answer. */
     out.print ("The beam is reflected from ");
     if (ct==1) out.print ("1 mirror");
     else out.print (ct+" mirrors");
     out.println (", leaving the last mirror");
     out.println (
           "         at ("+df.format(sx)+","+df.format(sy)+
           ") with an angle of "+df.format(sd)+" degrees.");
     out.println ();
    }
  }
 }

/* Read reads in the input data.  It returns 0 if there is no data to
   read; 1 otherwise. */
 public static boolean Read () throws Exception {

  int i;

  sz = Integer.parseInt (nextThing()); /* number of mirrors */
  if (sz==0) return false;
  for (i=0; i < sz; i++) {/* the mirrors themselves */
   Mirrors[i] = new MT ();
   Mirrors[i].leftx = Double.parseDouble (nextThing());
   Mirrors[i].lefty = Double.parseDouble (nextThing());
   Mirrors[i].rightx = Double.parseDouble (nextThing());
   Mirrors[i].righty = Double.parseDouble (nextThing());
  }
  sx = Double.parseDouble (nextThing());
  sy = Double.parseDouble (nextThing());
  sd = Double.parseDouble (nextThing());
  ct = 0;
  return true;
 }

/* ge is a standard Gaussian Elimination algorithm that row-reduces
   (in this case) a 2x3 matrix. */
 public static void ge (double[][] M) {

  int r,c,maxr,row,col;
  double max;
  double T;

  for (r=0,c=0;r<2 && c<3;c++) {
   max = Math.abs (M[r][c]);
   for (maxr=r,row=r+1;row < 2;row++) {
    if (Math.abs (M[row][c]) > max) {
     max = Math.abs (M[row][c]);
     maxr = row;
    }
   }
   if (max > 1e-5) { /* 1e-5 to avoid round-off error */
    for (col=c;col < 3;col++) {
     T = M[r][col];
     M[r][col] = M[maxr][col];
     M[maxr][col] = T;
    }
    for (col=c+1;col < 3;col++) M[r][col] /= M[r][c];
    M[r][c] = 1;
    for (row=0;row < 2;row++) {
     if (row==r) continue;
     for (col=c+1;col < 3;col++) M[row][col] -= M[row][c]*M[r][col];
     M[row][c] = 0;
    }
    r++;
   }
  }
 }

/* Process bounces the light off the nearest mirror, if possible.  It
   returns false if there is no bounce, true if there is. */
 public static boolean Process () {

  boolean found=false;
  int i, closest=0;
  double[][] M = new double[2][3];
  double closestpos=0, closestt=0;

  for (i=0; i<sz; i++) { /* For each mirror, set up equations in the */
   M[0][0] = Math.cos(sd*Math.PI/180);
                     //matrix to decide if they intersected.
   M[0][1] = Mirrors[i].leftx - Mirrors[i].rightx;
   M[0][2] = Mirrors[i].leftx - sx;
   M[1][0] = Math.sin(sd*Math.PI/180);
   M[1][1] = Mirrors[i].lefty - Mirrors[i].righty;
   M[1][2] = Mirrors[i].lefty - sy;
   ge (M); /* Use Gaussian Elimination to solve equations */
   if (ValidIntersection (M) && (!found || M[0][2] < closestpos)) {
    closest = i; /*If the beam does hit and its closer than the others*/
    closestpos = M[0][2]; /* so far, update information. */
    closestt = M[1][2];
    found = true;
   }
  }
  if (!found) return false; /* If no bounce, return */
  sx = Mirrors[closest].leftx + /* Update the light beam to reflect */
       closestt*(Mirrors[closest].rightx-Mirrors[closest].leftx);
  sy = Mirrors[closest].lefty + /* it's new origin and direction. */
      closestt*(Mirrors[closest].righty-Mirrors[closest].lefty);
  sd = 2*Math.atan2(Mirrors[closest].righty-Mirrors[closest].lefty,
           Mirrors[closest].rightx-Mirrors[closest].leftx)*180/Math.PI
       - sd;
  while (sd < 0) sd += 360;
  while (sd >= 360) sd -= 360;
  ct++;
  return true;
 }

/* ValidIntersection examines a row-reduced matrix to see whether a
   beam could reflect off that mirror and returns a boolean to that
   effect. */
 public static boolean ValidIntersection (double[][] M) {

  if (M[0][0] != 1 || M[1][1] != 1) return false;
                            /* light, mirror parallel*/
  if (M[0][2] < 1e-5) return false; /* mirror is behind light origin */
  if (M[1][2] < -1e-5 || M[1][2] > 1+1e-5) return false;
         /* light goes past*/
  return true; /* edge */
 }

/* nextThing returns the next token in the input file. */
 public static String nextThing () throws Exception {

  while (!st.hasMoreTokens()) st = new StringTokenizer (in.readLine());
  return st.nextToken();
 }
}