#Q108. 「一本通 3.7 例 2」单词游戏

「一本通 3.7 例 2」单词游戏

Description

From ICPC CERC 1999/2000, with modifications.

There are NN plates, each with a word consisting of lowercase English letters written on it. You need to arrange these plates in a suitable order such that for any two adjacent plates, the last letter of the word on the previous plate matches the first letter of the word on the next plate. Write a program to determine if this requirement can be met. If possible, provide a valid sequence.

Input Format

Multiple test cases. The first line gives the number of test cases TT. For each test case, the first line provides the number of plates NN, followed by NN lines each containing a lowercase string. The same string may appear multiple times.

Output Format

If a valid arrangement exists, output Ordering is possible.. Otherwise, output The door cannot be opened..

Sample 1

3
2
acm
ibm
3
acm
malform
mouse
2
ok
ok

The door cannot be opened.
Ordering is possible.
The door cannot be opened.

Constraints and Hints

1N105,S10001 \le N \le 10^5, |S| \le 1000