import java.util.ArrayList;
import java.util.List;

public class Sample99 {
	public enum Direction {
		左上, 上, 右上, 右, 右下, 下, 左下, 左,
	}

	private final String[] matrix_;

	public Sample99(String[] matrix) {
		matrix_ = matrix;
	}

	public AnswerData[] search(String str) {
		List<AnswerData> result = new ArrayList<AnswerData>();
		char[] input = str.toCharArray();
		for (int y = 0; y < matrix_.length; y++) {
			char[] cs = matrix_[y].toCharArray();
			for (int x = 0; x < cs.length; x++) {
				if (cs[x] != input[0]) continue;

				for (Direction d: Direction.values()) {
					switch (d) {
						case 左上:
							if (x < input.length - 1) break;
							if (y < input.length - 1) break;
							if (search(input, x, y, -1, -1)) {
								result.add(new AnswerData(x, y, d));
							}
							break;
						case 上:
							if (y < input.length - 1) break;
							if (search(input, x, y, 0, -1)) {
								result.add(new AnswerData(x, y, d));
							}
							break;
						case 右上:
							if (x > cs.length - input.length) break;
							if (y < input.length - 1) break;
							if (search(input, x, y, 1, -1)) {
								result.add(new AnswerData(x, y, d));
							}
							break;
						case 右:
							if (x > cs.length - input.length) break;
							if (search(input, x, y, 1, 0)) {
								result.add(new AnswerData(x, y, d));
							}
							break;
						case 右下:
							if (x > cs.length - input.length) break;
							if (y > matrix_.length - input.length) break;
							if (search(input, x, y, 1, 1)) {
								result.add(new AnswerData(x, y, d));
							}
							break;
						case 下:
							if (y > matrix_.length - input.length) break;
							if (search(input, x, y, 0, 1)) {
								result.add(new AnswerData(x, y, d));
							}
							break;
						case 左下:
							if (x < input.length - 1) break;
							if (y > matrix_.length - input.length) break;
							if (search(input, x, y, -1, 1)) {
								result.add(new AnswerData(x, y, d));
							}
							break;
						case 左:
							if (x < input.length - 1) break;
							if (search(input, x, y, -1, 0)) {
								result.add(new AnswerData(x, y, d));
							}
							break;
					}
				}
			}
		}
		return result.toArray(new AnswerData[0]);
	}
	private boolean search(char[] input, int x, int y, int dx, int dy) {
		for (int index = 1; index < input.length; index++) {
			if (matrix_[y + dy * index].charAt(x + dx * index) != input[index]) {
				return false;
			}
		}
		return true;
	}

	private static class AnswerData {
		public final int x;
		public final int y;
		public final Direction d;
		
		public AnswerData(int x, int y, Direction d) {
			this.x = x;
			this.y = y;
			this.d = d;
		}
	}

	public static void main(String[] args) {
		Sample99 s = new Sample99(new String[] {
				"リオウウリウ",
				"ウオリウオリ",
				"オリリオリウ",
				"リリオオウオ",
		});
		AnswerData[] datas = s.search("ウオリ");
		for (AnswerData d: datas) {
			System.out.format("(%d, %d), %s%n", d.x, d.y, d.d.name());
		}
	}
}
