1.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* Problem: 10129 Play on Words
* Link:
http://w3-o.cs.hm.edu/~logofatu/FWPACM/SS11/contestSimulation18_05.pdf
*
* @author Rolf Schirm
* @version 1.0, 05/30/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.336
*/
public class Main {

private static final int letterCount = 'z' - 'a' + 1;

public static void main(String... args) throws Exception {
final BufferedReader reader = new BufferedReader(new
InputStreamReader(System.in));

final int tcCount = Integer.parseInt(reader.readLine());
for(int xyz = 0; xyz < tcCount; xyz++) {
final int lineCount = Integer.parseInt(reader.readLine());

final int[] firstCount = new int[letterCount];
final int[] lastCount = new int[letterCount];
final int[][] edges = new int[letterCount][letterCount];

// Read the input
for(int i = 0; i < lineCount; i++) {
final String line = reader.readLine();
final int firstChar = line.charAt(0) - 'a';
final int lastChar = line.charAt(line.length() - 1) - 'a';

firstCount[firstChar]++;
lastCount[lastChar]++;
edges[firstChar][lastChar]++;
}

boolean possible = true;
boolean haveFirst = false;
boolean haveLast = false;

// Check first and last char
for(int i = 0; i < letterCount && possible; i++) {
final int fc = firstCount[i];
final int lc = lastCount[i];

// Special case
if(fc != lc) {
// First char detected
if(fc + 1 == lc && !haveFirst) {
haveFirst = true;

// Last char detected
} else if(fc == lc + 1 && !haveLast) {
haveLast = true;

// More then one first or last char
} else {
possible = false;
}
}
}

// Ordering is possible up to now
if(possible) {
boolean[] charUsed = new boolean[letterCount];
List<Integer> queue = new LinkedList<Integer>();

// Find any edge for starting
int start = -1;
for(int i = 0; i < letterCount; i++) {
for(int j = 0; j < letterCount; j++) {
if(edges[i][j] > 0) {
start = i;
queue.add(start);
break;
}
}
}

// Check all edges to the end
while(!queue.isEmpty()) {
final int element = queue.remove(0);

// Check all edges
for(int i = 0; i < letterCount; i++) {
// Edge exists
if(edges[element][i] > 0) {
// Remove edge
edges[element][i] = 0;

// Only add if char is not used
if(!charUsed[i]) {
// Add char to the queue
queue.add(i);

// Set char to used
charUsed[i] = true;
}
}
}
}

// Check all edges to the start
queue.add(start);
while(!queue.isEmpty()) {
final int element = queue.remove(0);

// Check all edges
for(int i = 0; i < letterCount; i++) {
// Edge exists
if(edges[i][element] > 0) {
// Remove edge
edges[i][element] = 0;

// Only add if char is not used
if(!charUsed[i]) {
// Add char to the queue
queue.add(i);

// Set char to used
charUsed[i] = true;
}
}
}
}

// Check if all edges are removed
for(int i = 0; i < letterCount && possible; i++) {
for(int j = 0; j < letterCount && possible; j++) {
if(edges[i][j] > 0) {
possible = false;
}
}
}

// Print output
if(possible) {
System.out.println("Ordering is possible.");
} else {
System.out.println("The door cannot be opened.");
}
} else {
System.out.println("The door cannot be opened.");
}
}
}
}