Under construction

Still being built. Things may change

Tanks and Pipes

Time limit2sMemory limit512 MB

Summary
Given tank radius, pipe radius, axis offset, and pipe slope, find the length of the curve where the pipe meets the tank wall.
Level

Medium7 of 10

Topics
Geometry, Math
Solved
No attempts yet

Problem

The Frobozz Magic Tank and Pipe Company builds specialty tanks and reaction vessels. Hurricane Entharion nearly destroyed Quendor Refinery #3, and every pipe and tank there needs an upgrade. The sales engineers use a bidding program for this project, and that program must be upgraded too. One estimate element is attaching a pipe to a tank (or reaction vessel). The pipe may end at the tank or pass through the tank wall.

The most common case is a pipe whose axis is perpendicular to the cylindrical tank axis (A). Less often, the pipe axis is not perpendicular to the tank axis (B), or it is offset from the tank axis (C), or both (D). The company has enough data to handle type A directly. For the other types, it wants a model based on the tank and pipe thicknesses, the angle between the pipe and the tank surface, any lining in the tank, and the length of the joint between the pipe and tank. That joint length sets the length of the cut in the tank wall and the length of the weld.

Write a program that finds the length of the intersection of the pipe with the cylindrical tank wall, given the sizes of the pipe and tank and the offset and pipe angle.

Input

The first line contains a single integer PP (1≤P≤1001 \le P \le 100), the number of data sets. Each data set is processed independently.

Each data set is one line containing the data set number KK, followed by four floating point values: the radius RTR_T of the tank, the radius RPR_P of the pipe, the perpendicular offset from the axis of the cylinder to the axis of the pipe, and the slope of the pipe axis with respect to the plane perpendicular to the cylinder axis.

For a given point on the pipe axis, dperpd_{perp} is the perpendicular distance to the plane perpendicular to the cylinder axis, and dplaned_{plane} is the distance along that plane. The slope of the pipe axis is dperp/dplaned_{perp}/d_{plane}.

Output

For each data set, print one line with the data set number KK, followed by the length of the intersection of the pipe with the cylindrical tank wall, as a floating point value with 3 decimal places.

Examples1

  1. Example 1

    Input
    4
    1 4 1 0 0
    2 4 1 0 1
    3 4 1 2.5 0
    4 4 1 2.5 1
    
    Expected output
    1 6.308
    2 7.669
    3 7.429
    4 9.338