import java.io.*; import java.util.*; public class DefendTheNation { private static final double G = 9.8; private static final int P = 10; // precision in String.format private static final double EPS = 1.0e-08; private static final Scanner cin = new Scanner(System.in); public static void main(String[] args) { int nCase = cin.nextInt(); for(int iCase = 1; iCase <= nCase; iCase++) { double dis = cin.nextDouble(); double tau = cin.nextDouble(); double v1 = cin.nextDouble(); double theta1 = cin.nextDouble(); double v2 = cin.nextDouble(); double[] output = solve(dis, tau, v1, theta1, v2); if(iCase > 1) { System.out.println(); } System.out.println("Case " + iCase + ":"); if(output != null) { System.out.println(String.format("Fire at %." + P + "f degree(s).", output[1])); System.out.println(String.format("Projectile destroyed in %." + P + "f second(s).", output[0])); } else { System.out.println("Projectile reaches the land."); } } } private static double[] solve(double dis, double tau, double v1, double theta1, double v2) { theta1 = Math.toRadians(theta1); double alpha = 1.0 / (v1 * Math.cos(theta1)); double s1 = v1 * v1 * Math.sin(2.0 * theta1) / G; double vv = v2 * v2 / G; double[] range = null; { double a = alpha * alpha * G * vv - 1.0; double b = 2.0 * dis - alpha * alpha * G * vv * s1; double c = vv * vv - dis * dis; range = solveCmp(a, b, c); if(range == null) { return null; } } int n_tau = 0; double[] t_tau = null; double[] x_tau = null; double[] a_tau = null; { double x = v1 * tau * Math.cos(theta1); double y = v1 * tau * Math.sin(theta1) - 0.5 * G * tau * tau; double phi = Math.atan2(y, dis - x); double l = Math.hypot(y, dis - x); double v0x = v1 * Math.cos(theta1); double v0y = v1 * Math.sin(theta1) - G * tau; double theta0 = Math.atan2(v0y, v0x); double v0 = Math.hypot(v0y, v0x); double a = v0 * v0 - v2 * v2; double b = - 2.0 * v0 * l * Math.cos(theta0 + phi); double c = l * l; t_tau = solveEqn(a, b, c); if(t_tau != null) { n_tau = t_tau.length; x_tau = new double[n_tau]; a_tau = new double[n_tau]; for(int i = 0; i < n_tau; i++) { double p = v0 * t_tau[i]; double q = l; double r = v2 * t_tau[i]; double cosA = (q * q + r * r - p * p) / (2.0 * q * r); a_tau[i] = Math.signum(theta0 + phi) * Math.acos(cosA) + phi; x_tau[i] = v1 * (t_tau[i] + tau) * Math.cos(theta1); } } } for(int i = 0; i < range.length; i += 2) { if(compare(range[i], s1) > 0) break; double p = Math.min(Math.max(range[i + 0], 0.0), s1); double q = Math.min(Math.max(range[i + 1], 0.0), s1); // Delta(p) >= tau ? if(p != 0.0) { double t = alpha * p; double x = p; double y = 0.5 * alpha * alpha * G * x * (s1 - x); double xx = dis - x; double yy = y; double zz = vv * vv - 2.0 * vv * yy - xx * xx; /* if(compare(zz, 0.0) != 0) throw new RuntimeException("bug detected (zz)"); */ double tt = (2.0 / G) * (vv - yy); /* if(compare(tt, 0.0) < 0) throw new RuntimeException("bug detected (tt)"); */ tt = Math.sqrt(Math.max(tt, 0.0)); if(compare(tt + tau, t) <= 0) { return new double[] { t, Math.toDegrees(Math.atan2(vv, xx)) }; } } // Delta(x) == tau ? if(t_tau != null) { for(int j = 0; j < n_tau; j++) { if(compare(x_tau[j], p) < 0) { continue; } if(compare(x_tau[j], q) > 0) { continue; } if(compare(t_tau[j], 0) < 0) { continue; } return new double[] { t_tau[j] + tau, Math.toDegrees(a_tau[j]) }; } } } return null; } // a * x^2 + b * x + c == 0 private static double[] solveEqn(double a, double b, double c) { if(compare(a, 0.0) == 0) { if(compare(b, 0.0) == 0) { return null; } return new double[] { - c / b }; } double d = b * b - 4.0 * a * c; if(compare(d, 0.0) < 0) return null; double d_sqrt = Math.sqrt(Math.max(d, 0.0)); double[] x = new double[2]; if(b < 0.0) { x[0] = -(b - d_sqrt) / (2.0 * a); x[1] = -(2.0 * c) / (b - d_sqrt); } else { x[0] = -(b + d_sqrt) / (2.0 * a); x[1] = -(2.0 * c) / (b + d_sqrt); } /* if(compare(a * x[0] * x[0] + b * x[0] + c, 0.0) != 0) throw new RuntimeException("x[0]"); if(compare(a * x[1] * x[1] + b * x[1] + c, 0.0) != 0) throw new RuntimeException("x[1]"); */ if(x[0] > x[1]) { double temp = x[0]; x[0] = x[1]; x[1] = temp; } return x; } // a * x^2 + b * x + c >= 0 private static double[] solveCmp(double a, double b, double c) { if(compare(a, 0.0) == 0) { if(compare(b, 0.0) == 0) { if(compare(c, 0.0) >= 0.0) { return new double[] { Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY }; } else { return null; } } else { if(b > 0.0) { return new double[] { -(c / b), Double.POSITIVE_INFINITY }; } else { return new double[] { Double.NEGATIVE_INFINITY, -(c / b) }; } } } else { double[] x = solveEqn(a, b, c); if(x == null) { if(a > 0.0) { return new double[] { Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY }; } else { return null; } } else { if(a > 0.0) { return new double[] { Double.NEGATIVE_INFINITY, x[0], x[1], Double.POSITIVE_INFINITY }; } else { return x; } } } } private static int compare(double x, double y) { if(x - y > EPS) { return +1; } if(y - x > EPS) { return -1; } return 0; } }