ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

Ural Championship 2011

About     Problems     Submit solution     Judge status     Standings
Contest is over

G. Babel Fish

Time limit: 0.5 second
Memory limit: 64 MB
The Babel fish is a rare and very useful creature, which saved Arthur Dent in his travels around the Galaxy more than once. If you insert it into your ear, you'll be able to understand representatives of any race in the Galaxy as if they spoke your own language.
Upon his return to the Earth, Arthur took the fish out of his ear and decided to keep it in case his friend Ford Prefect arrived unexpectedly and dragged him off on a new travel. Arthur thought it would be best to keep the fish in the tank the intelligent dolphins had given him. Then he would be able to have the tank with him even if he went far away from home in his car.
The tank was a rectangular parallelepiped with a square base and open top. To control the amount of water in the tank, Arthur mounted a sensor for registering the water level at each of its four vertical edges.
Since the state of British country roads was far from ideal, the car tilted often and the water surface was not always parallel to the bottom of the tank, which produced unequal readings of the sensors. Arthur had to invent some method of calculating the amount of water in the tank.
Problem illustration

Input

The first line contains the number of tests t (1 ≤ t ≤ 104). In each of the following t lines you are given five integers: the length of the base square of the tank and the water levels at the vertical edges. All the integers are nonnegative and do not exceed 106. The edges are described in the order shown in the figure.

Output

For each test output the volume of water in the tank if it is determined uniquely, “error” if the data are inconsistent, and “ambiguous” if the answer cannot be found uniquely. All the numbers should be given with absolute or relative error of at most 10−6.

Sample

inputoutput
2
10 2 3 4 3
10 2 3 3 3
300.000
error
Problem Author: Denis Dublennykh
Problem Source: Ural Championship 2011
To submit the solution for this problem go to the Problem set: 1836. Babel Fish