Tunnelling the Earth

Time limit1sMemory limit128 MB

Problem

There are many ways to move people from place to place: cars, bikes, boats, trains, planes, and so on. For very long distances people usually fly, but a plane has to follow the curved surface of the Earth. The trip would be shorter if the traveller went in a straight line from one point to the other through a tunnel bored through the Earth.

For example, travelling from Waterloo to Cairo covers $9293521$ metres along the great-circle route over the surface, but only $8491188$ metres along the straight line through the Earth.

Assume the Earth is a perfect sphere with radius $6371009$ metres.

Input

The first line contains a single integer, the number of test cases. Each test case is one line with four floating-point numbers: the latitude and longitude of the origin, followed by the latitude and longitude of the destination, all in degrees. Positive values mean North latitude and East longitude; negative values mean South latitude and West longitude.

Output

For each test case, output one line with a single integer: the difference between the great-circle distance over the surface and the straight-line distance through the Earth, in metres, rounded to the nearest integer.