BrainFuckVM
Given a brainfuck program, determine whether it terminates or enters an endless loop. A brainfuck interpreter has a data array (consisting of unsigned 8-bit integers) with an index, the so called "data index "; the entry of the array pointed to by the data index is the so called "current entry". A brainfuck program consists of a sequence of the following eight instructions:
Interpretation of a brainfuck program starts at the first instruction, and terminates if the instruction pointer leaves the end of the program. After an instruction is executed, the instruction pointer advances to the instruction to the right (except, of course, if the loop instructions [ or ] cause a jump).
In addition to the program, you will be given the size of the data array. The entries of the data array shall be unsigned 8-bit integers, with usual over- or underow behaviour. At the start of the program, the data array entries and the data index shall be initialized to zero.
Incrementing or decrementing the data index beyond the boundaries of the data array shall make it re-enter the data array at the other boundary; e.g. decrementing the data index when it is zero shall set it to the size of the data array minus one.
The [ and ] instructions de_ne loops and are allowed to nest. Every given program will be wellformed, i.e. when traversing the program from left to right, the number of [ instructions minus the number of ] instructions will always be greater or equal zero, and at the end of the program it will be equal to zero.
For the purposes of the problem, discard the output of the interpreted program^1.
____________
^1 For purposes of debugging, you may examine it. The third program from the sample input would print "ICPC"; the fourth program, when given an arbitrary string, will print a brainfuck program, that in turn will print said arbitrary string when executed.
Input
The input starts with a line containing the number of test cases t (0 < t ≤ 20). Each test case consists of three lines. The first line contains three integers sm, sc, si, describing the size of the memory, the size of the program code and the size of the input (0 < sm ≤ 100 000; 0 < sc, si < 4 096).
The second line contains the brainfuck program code to be executed; it consists of sc characters. The third line contains the input of the program, as text (only printable, non-whitespace characters). Once the program has consumed all available input, the input instruction shall set the current cell to 255.
Output
For each test case, print one line, containing either "Terminates" or "Loops", depending on whether the program either terminates after a finite number of steps, or enters an endless loop. If the program loops, also print the indices (0-based) of the two [ and the ] symbols in the code array that correspond to the endless loop. You may safely assume that after 50 000 000 instructions, a program either terminated or hangs in an endless loop, which then was executed at least once. During each iteration of the endless loop at most 50 000 000 instructions are executed.