1. 
/*
* ACM Contest training
* Problem: 466 - Mirror, Mirror
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=407
*
* @author Christoph Goettschkes
* @version 1.0, 01/06/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.120
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {

static char[][] in;
static char[][] out;
static int size;

public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int tc = 0;

do
{
tc++;
size = Integer.parseInt(reader.readLine());
in = new char[size][size];
out = new char[size][size];
for (int i = 0; i < size; i++) {
String[] cur = reader.readLine().split(" ");
in[i] = cur[0].toCharArray();
out[i] = cur[1].toCharArray();
}

if (isPreserved()) {
System.out.println("Pattern "+tc+" was preserved.");
continue;
}

String rotated = isRotated();
if (rotated != null) {
System.out.println("Pattern "+tc+" was rotated "+rotated+" degrees.");
continue;
}

if (isReflected()) {
System.out.println("Pattern "+tc+" was reflected vertically.");
continue;
}

in = getReflected();

rotated = isRotated();
if (rotated != null) {
System.out.println("Pattern "+tc+" was reflected vertically and rotated "+rotated+" degrees.");
continue;
}

System.out.println("Pattern "+tc+" was improperly transformed.");

} while(reader.ready());
}

static boolean isPreserved() {
for (int row = 0; row < size; row++) {
if (!Arrays.equals(in[row], out[row]))
return false;
}
return true;
}

static String isRotated() {
boolean rotated90 = true;
boolean rotated180 = true;
boolean rotated270 = true;
for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) {
if (in[row][col] != out[col][size - 1 - row])
rotated90 = false;
if (in[row][col] != out[size - row - 1][size - col - 1])
rotated180 = false;
if (in[row][col] != out[size - 1 - col][row])
rotated270 = false;
}
if (!rotated90 && !rotated180 && !rotated270)
return null;
}

if (rotated90)
return "90";

if (rotated180)
return "180";

if (rotated270)
return "270";

return null;
}

static boolean isReflected() {
for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) {
if (in[row][col] != out[size - 1 - row][col])
return false;
}
}
return true;
}

static char[][] getReflected() {
char[][] tmp = new char[size][size];
for (int row = 0; row < size; row++) {
System.arraycopy(in[row], 0, tmp[size - 1 - row], 0 , size);
}
return tmp;
}
}

/*
Test Data:
8
........ ....X..X
..XXX... ....X..X
..XXX... .XX.X..X
........ .XX.XXXX
XXXXXXXX .XX.XXXX
...XX... ....X..X
...XX... ....X..X
XXXXXXXX ....X..X
10
.......... ..........
.......... ..........
.......... ..........
.......... ....XX....
.......... ..........
.......... ..........
....XX.... ..........
.......... ..........
....X..... ..X.......
.......... ..........
10
.......... ..........
.......... ..........
.......... ..........
.......... ..X.......
.......... ...X......
.......... ...X......
....XX.... ..........
...X...... ..........
.......... ..........
.......... ..........
10
XXXXXXXXXX X........X
.......... .........X
.......... .........X
.......... .........X
.......... ...X.....X
.......... ...X.....X
....XX.... ..X......X
...X...... .........X
.......... .........X
.........X .........X
1
. .
1
X X
1
X .
1
. X
2
.X X.
.X X.
3
X.. ..X
.X. .X.
..X X..
3
X.X ..X
.X. .X.
..X X.X
3
X.X X..
XX. .XX
..X X.X
3
X.X XX.
XX. .X.
..X X.X
5
X...X ....X
.X... ...X.
...X. .X...
..X.X ..X..
....X XX..X
6
....XX X....X
...X.. X.X...
XX..X. .X..X.
..X... ...X.X
...X.. ..X...
..X..X ..X...
2
X. X.
.X .X
4
..X. ...X
XX.. ....
.... XX..
...X ..X.
5
X.... .X...
.X... ..X..
.X... ..X..
...X. ....X
....X X....
4
.X.. ..X.
.X.X X...
.... ..XX
..X. ....
2
.. XX
XX ..

Output:
Pattern 1 was reflected vertically and rotated 90 degrees.
Pattern 2 was improperly transformed.
Pattern 3 was rotated 90 degrees.
Pattern 4 was reflected vertically and rotated 270 degrees.
Pattern 5 was preserved.
Pattern 6 was preserved.
Pattern 7 was improperly transformed.
Pattern 8 was improperly transformed.
Pattern 9 was rotated 180 degrees.
Pattern 10 was rotated 90 degrees.
Pattern 11 was rotated 90 degrees.
Pattern 12 was rotated 180 degrees.
Pattern 13 was reflected vertically and rotated 90 degrees.
Pattern 14 was rotated 90 degrees.
Pattern 15 was rotated 270 degrees.
Pattern 16 was preserved.
Pattern 17 was reflected vertically.
Pattern 18 was improperly transformed.
Pattern 19 was reflected vertically and rotated 270 degrees.
Pattern 20 was rotated 180 degrees.
*/