private static void begin() {
        Scanner sc = new Scanner(System.in);
        int nTestCases = Integer.parseInt(sc.nextLine());
        sc.nextLine(); // process empty line.

        /* @formatter:off
         * Decides how to search the word in the matrix.
         * 0,1 -> horizontally to the right
         * 1,0 -> vertically to the bottom
         * 1,1 -> diagonally to the right and bottom
         * 1,1 -> diagonally to the left and bottom
         */
        // @formatter:on
        int[][] dirs = {{0, 1}, {1, 0}, {1, 1}, {1, -1}};

        for (int t = 0; t < nTestCases; ++t) {
            int m = sc.nextInt();
            int n = sc.nextInt();
            sc.nextLine();

            // Read in the characters.
            char[][] matrix = new char[m + 1][n + 1];
            for (int r = 1; r <= m; ++r) {
                String line = sc.nextLine().toLowerCase();
                for (int c = 1; c <= n; ++c) {
                    matrix[r][c] = line.charAt(c - 1);
                }
            }

            int nWords = Integer.parseInt(sc.nextLine());
            StringBuilder testCaseOutput = new StringBuilder();
            // Read in the words and find its best position.
            while (--nWords >= 0) {
                String word = sc.nextLine().toLowerCase();
                List<Pos> positions = new LinkedList<Pos>();
                for (int dir[] : dirs) {
                    Pos pos = searchWord(matrix, word, dir[0], dir[1]);
                    if (pos != null) {
                        positions.add(pos);
                    }
                }

                // Store the best position of the word.
                if (positions.size() > 0) {
                    Collections.sort(positions);
                    testCaseOutput.append(positions.get(0)).append("\n");
                }
            }

            // Output the best positions of the words.
            if (testCaseOutput.length() > 0) {
                System.out.print(testCaseOutput);
            }

            if (t < nTestCases - 1) {
                System.out.println();
                sc.nextLine(); // process the empty line
            }
        }
    }