1614 - Problem E. Mahjong   

Description

There are many variations of mahjong. In many places, players often observe one version and are either unaware of other variations or claim that different versions are incorrect. In order to simplify this problem, we consider 13 tiles with only one suit.
We use a single integer (1 to 9) to represent a tile in this simplified problem, and consider below melds only:
Pong A set of three identical tiles, like 7 7 7.
Chow A meld of three tiles in sequence, like 1 2 3.
Eye A pair, like 9 9.
A player wins by creating a hand which can be decompose into four of Pong and/or Chow, with a single Eye.

Input

The first line of the input will be an integer T (1<=T<=1000), denoting the number of test cases.
Each case has a single line containing 13 integers, which are the tiles you have already had.

Output

For each case, output all the tiles that can make you win in one line in ascending order, separated by one space.
If there are no solution, please output “0” in a single line.

Sample Input  Download

Sample Output  Download

Tags




Discuss