A Tale of Two Right Angled Triangles

All submissions for this problem are available.
You are given two right angled triangles. You are given their side lengths. The first triangle is ABC, where side AB is the hypotenuse. Length of AB is c, that of AC is b, and that of BC is a. Similarly, the second triangle is DEF, where DE is the hypotenuse. Length of DE is f, that of DF is e, and that of EF is d.
First we define minimum area enclosing axisparallel rectangle of some figures. It will be a rectangle which is axis parallel (i.e. each of its sides should be parallel to x or y axis) that encloses all the figures and has the minimum possible area. By enclosing, we mean that all the figures should be inside the rectangle.
You have to find a set of coordinates to assign to the points A, B, C, D, E, F such that the minimum area enclosing axisparallel rectangle of the two triangles has sides L and R, i.e. one side is of length L, and the other is of length R. Also, each of the sides AC, BC, DF, EF should be parallel to either x or y axis. If it is not possible to assign the coordinates, output 1.
Input
 The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
 The only line of each test case contains eight space separated integers denoting the lengths a, b, c, d, e, f, L, R.
Output
For each test case, either output 1 if it is impossible to assign the coordinates. Otherwise, output six lines each containing two space separated integers corresponding to the coordinates of points A, B, C, D, E, F in that order. You can output any possible coordinates that have their absolute values less than or equal to 10^{9}.
Constraints
 1 ≤ T ≤ 10^{5}
 1 ≤ a, b, c, d, e, f, L, R ≤ 10^{8}
 a^{2} + b^{2} = c^{2}
 d^{2} + e^{2} = f^{2}
Example
Input 2 3 4 5 3 4 5 4 4 3 4 5 3 4 5 2 4 Output 2 5 5 1 2 1 2 4 6 1 6 4 1
Explanation
Testcase 1: The output corresponds to the image shown below:
Notice that all the 6 side lengths are maintained, and the sides AC, BC, DF, EF are all axisparallel. The minimum area enclosing axisparallel rectangle of these two triangles is shown in the next image:
Notice that this is a rectangle with side lengths 4 and 4, just as we wanted. Hence this is a valid output.
Author:  admin2 
Tags  admin2, easy, gwr17rol 
Date Added:  19122017 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions