Time limit
2s
Memory limit
128 MB
Two tetrahedra are given. Each face has a color represented by a positive integer.
A tetrahedron is described by four integers. The first integer is the color of the base face, and the next three integers are the colors of the three side faces around that base in clockwise order.
If one tetrahedron can be rotated in space so that the color arrangement of every face matches the other tetrahedron, the two tetrahedra are considered the same. For each data set, determine whether the two tetrahedra are the same.
The first line contains the number of data sets K. 1 <= K <= 1,000.
Each of the next K lines contains 8 positive integers describing two tetrahedra. The first four integers describe the first tetrahedron, and the last four describe the second tetrahedron. For each tetrahedron, the first integer is the color of the base face, followed by the colors of the side faces in clockwise order.
Each color number is a positive integer not greater than 60,000.
For each data set, output one line. Print 1 if the two tetrahedra are the same, and 0 otherwise.