Outsourcing
Mr. Cooper is a manufacturer of science fi ction action gures and he thinks that his local factory causes too many costs. He once heard of certain foreign countries where workers are much less expensive and also more dedicated. So he decided to look for an available action gure factory in some low-wage country to follow the current trend of Outsourcing.
It is of course indispensable for him to know if the new factory is capable of producing exactly the same sorts of action gures as the current one. The manufacturing process is organised in terms of assembly stations and transfer stations. An assembly station receives parts from a transfer station, performs a speci c operation on the parts and delivers it to a transfer station. The factories have one starting transfer station delivering raw parts and one nal transfer station receiving the completed action fi gures.
One sort of action gures needs a precise sequence s_1, s_2, s_3, ..., s_l of assembly operations. A factory can produce these action gures if there are transfer stations t_0, t_1, ..., t_l such that t_0 is the starting station, t_l is the nal station, and for all 1 ≤ i ≤ l there is an assembly station that receives from t_{i-1}, delivers to t_i, and performs operation s_i.
Hence, Mr. Cooper wants to know if the local factory and the foreign factory can produce exactly the same sorts of action gures. He recognizes that answering this question may be an involved challenge. So, he decides to spend an amount of his yet to save money on you, to make you develop a computer solution for his problem.
Input
Input starts with a line containing one integer t, the number of test cases (0 < t ≤ 100). Each test case starts with a line of six integers M_1, N_1, K_1, M_2, N_2 and K_2, where the local factory has M_1 assembly stations, N_1 transfer stations and K_1 different assembly operations (1 ≤ M_1 ≤ 10^5, 1 ≤ N_1 ≤ 250, 1 ≤ K_1 ≤ 250). The transfer stations are numbered from 0 to N_1-1 the nal station. Then input is followed by M_1 lines specifying the assembly stations of the local factory. Every line contains three integers, T_in, T_out, S, where T_in is the transfer station delivering to the assembly station, T_out is the transfer station receiving the assembly results and S gives the performed operation by a number between 0 andK_1-1. For every transfer station it is guaranteed that there are not two receiving assembly stations performing the same operation. The foreign factory is described analogously by M_2, N_2 and K_2 and consequently the next M_2 lines of input describe the assembly stations of the foreign factory.
Output
For every test case print a line containing "eligible" if the local and the foreign factory are capable of manufacturing exactly the same action gures and otherwise print "not eligible".