﻿ Fuzhou University OnlineJudge ﻿
Problem 1660 Four teams' military war game chess

## Problem Description

Daxia likes to play four teams’ military war game chess very much. The brief introduction of four teams’ military war game chess as follow:
This kind of chess is composed of four teams represented by four different colors, which hold a total of 100 soldiers. And the game is for four or five persons. It is very interesting.
Each person commands an army, and who sits the two opposite seats can ally to fight with the other ally allying by the other two teams. And the rest person is the referee. His judgment is based on the position of the soldier in the army,. If they are in the same position, they will be knocked out together.
At the beginning of the game, the player should stand his pieces of chess back to back on the board within the game limits. The player can arrange his army at his own will. After the game begins , one person arrange his soldier on duty to carry out his order. When it meet the enemy’s piece of chess, it needs the referee to judge and give a result. The higher one will go on living the board while the other one should leave the game. There’s the railway, in the game. So the soldier can run on it as long as no obstacle, but only run in straight line. The sapper can run on it without direction limit unless it has obstacle. But on the turnpike every piece can only move one step a time. When any piece of chess is in the barracks, no one can attack it while it can attack any enemy around it. The ensign should be revealed as soon as your commandant was killed by the enemy. Please attach importance to this: the bomb must not be put in the first row, and the landmine should be put in the last two rows. The ensign should be in the stronghold. Besides, the pieces in the stronghold mustn’t move.
 arms stand arms stand arms stand arms stand arms stand arms stand barrack arms stand barrack arms stand arms stand arms stand barrack arms stand arms stand arms stand barrack arms stand barrack arms stand arms stand arms stand arms stand arms stand arms stand arms stand stronghold arms stand stronghold arms stand
Every piece of chess has its own position, and the higher officer can win the lower one. The order is the commandant, the army commander, the divisional commander, the brigade commander, the regimental commander, the battalion commander, the company commander, the platoon leader and the sapper. And the sapper can overcome the landmine, but the landmine can kill all the officers expect the sapper. When the bomb is used to kill one piece of chess, the two will leave the game together. If your ensign is got by the enemy, you will lose the game. And if the ally lose all the ensigns, they of course lose the game. And the game is over.
Here is a picture of four teams’ military war game chess.
Now, give you a position of four teams’ military war game chess, please judge it is legal or illegal.

## Input

The first line is a positive number N, which is the number of test data. Each test has six lines, each line has five positive integers separated by space. The integers stand for officers as follow:
40: the commandant(The input ensure only one);
39: the army commander(The input ensure only one);
38: the divisional commander(The input ensure only two);
37: the brigade commander(The input ensure only two);
36: the regimental commander(The input ensure only two);
35: the battalion commander(The input ensure only two);
34: the company commander(The input ensure only three);
33: the platoon leader(The input ensure only three);
32: the sapper(The input ensure only three);
31: the landmine(The input ensure only three);
30: the ensign(The input ensure only one);
0: the bomb(The input ensure only two);
-1: the barrack(Ensure in five stable positions);

## Output

If the position is legal, output “Legal”, otherwise output “Illegal”.

## Sample Input

2 36 36 34 40 33 32 -1 32 -1 33 0 39 -1 34 33 35 -1 32 -1 34 0 35 38 37 31 38 30 37 31 31 36 36 34 40 33 32 -1 32 -1 33 0 39 -1 34 33 35 -1 32 -1 34 0 35 38 37 31 38 37 30 31 31

Legal Illegal

## Source

FOJ月赛-2008年10月

Submit  Back  Status  Discuss
﻿