There are multiple test cases in the input file.
The first line of each test case is one integer, T ( 2 ÷ T ÷ 26), the size of the alphabet. In each test case, the description of automaton A comes before that of automaton B. The description of each automaton starts with one line containing N (1 ÷ N ÷ 2000 ), the number of states in the automaton, followed by N lines, each line of the format: F, X
0, X
1, ˇ, X
T-1,
,-1 ÷ X
i < N). If F = 1, then the state is an accepting state; also, if X
i = -1, it means that the state has no corresponding transition available for character i. The start state of both finite automatons will always be state 0.
Two successive test cases are separated by a blank line. A case with a single 0 indicates the end of the input file, and should not be processed by your program.