SP89 HANGLET - Hang or not to hang

Description

Little Tom is learning how to program. He has just written some programs but is afraid to run them, because he does not know if they will ever stop. Please write a program to help him. This task is not as easy as it may seem, because Tom's programs are possibly not deterministic. Given a program written by Tom, your program should tell him whether his program can stop and if so, what is the shortest possible time before it stops. Tom's computer consists of 32 1-bit registers and the program consists of n instructions. The registers are numbered from 0 to 31 and the instructions are numbered from 0 to n-1. Below, MEM\[a\] stands for the contents of the a-th register, 0

Input Format

The input begins with the integer t, the number of test cases. Then t test cases follow. For each test case the first line of the input contains an integer n (1

Output Format

For each test case the first and only line of the output should contain the shortest possible running time of the program, measured in processor cycles. If the program cannot stop, output should contain the word HANGS.