You are on page 1of 2

Problem 8: Guarding the Settlement

(300 points)

After the victory over the humans, Jake Sully has permanently transferred
his consciousness to his Avatar form and is now the new leader of the Na’vi.
There is no more threat now, but the Na’vi sustained severe damages during
the battle with the humans. So it’s time to rebuild their homeland. Jake asks
his scientist friends to help design a new and more improved settlement for the
Na’vi. After a lot of deliberation, the final design is made. The total land
area is segmented in the form of a N × 4 grid and buildings are constructed
at the centre of each grid square. Assume that each square in the grid is of
equal dimension. Successive buildings that lie along neighbouring grid squares
are connected by a tunnel. Also, for every horizontal row of four buildings, the
fourth building is directly connected to the first and second buildings by two
seperate tunnels.

Now, they wish to place guards in some of the tunnels for security. A guard in
tunnel is responsible only for the security of the two houses at the end of the
tunnel. In order to optimize, they have decided to place guards in only some of
the tunnels so that each house is guarded by one and only one guard. They wish
to find out in how many ways they can choose the tunnels for placing guards so
that this task can be accomplished. Your job is to help them find the number
of ways they can choose tunnels to put the guards in.

Input format:

The first line contains the number of test cases T.

For each of the following T lines, there is one integer N specifying the size of
the N × 4 grid.

Output format:

For each test case, output a single integer (modulo 1000) denoting the num-
ber of ways in which the tunnels may be chosen for putting guards in. The
answer to each test case should appear on a new line.

Sample Input:


Sample Output: