private static void traverse(int row, int i, char[][] board) {
        Stack<Pair> stack = new Stack<Pair>();
        stack.push(new Pair(row, i));
        while (!stack.isEmpty()) {
            Pair p = stack.pop();
            board[p.row][p.col] = 'E';
            if (p.row - 1 > 0 && board[p.row - 1][p.col] == 'O') {
                stack.push(new Pair(p.row - 1, p.col));
            }
            if (p.row + 1 != board.length && board[p.row + 1][p.col] == 'O') {
                stack.push(new Pair(p.row + 1, p.col));
            }
            if (p.col - 1 > 0 && board[p.row][p.col - 1] == 'O') {
                stack.push(new Pair(p.row, p.col - 1));
            }
            if (p.col + 1 != board[p.row].length && board[p.row][p.col + 1] == 'O') {
                stack.push(new Pair(p.row, p.col + 1));
            }
        }
    }