Under construction

Still being built. Things may change

Nine Knights

Time limit1sMemory limit1024 MB

Summary
Checks whether a 5 by 5 board holds exactly nine knights with no two knights a knight's move apart.
Level

Easy2 of 10

Topics
Implementation, Array
Solved
No attempts yet

Problem

In the game of chess, knights are underwhelming but unique. No other piece moves like the knight in its 'L' shaped pattern. The knight moves in an L shape in any direction. It either moves two squares sideways and then one square up or down, or two squares up or down and then one square sideways.

Figure 1: The highlighted squares show all possible moves for a knight.

The knight changes the color of its square with each move. If it starts on a light square, it lands on a dark square after its move. In the diagram, the knight can move to any of the red squares.

The maximum number of knights that fit on a board is given by:

number of knights =(1/2)((n^2)+1) for n > 1 && n mod 2 == 1
(1/2)(n^2) for n > 2 && n mod 2 == 0

In the nine knights puzzle, nine knights are placed on a 5 by 5 board, even though up to thirteen fit. The knights are placed so that none of them attack one another. The board below shows an invalid solution:

...k.
...k.
k.k..
.k.k.
k.k.k

Input

The first line contains the number of test cases. Each test case is a 5 by 5 board given as five lines of characters. Each line consists only of '.' and 'k'. The '.' character is an empty square and 'k' is a knight. There is no blank line between boards.

Output

Print one line for each test case. Print "valid" if the given board is a valid solution to the nine knights problem. Otherwise, print "invalid".

Examples1

  1. Example 1

    Input
    2
    .....
    ...k.
    k.k.k
    .k.k.
    k.k.k
    
    ...k.
    ...k.
    k.k..
    .k.k.
    k.k.k
    
    Expected output
    valid
    invalid