# Problem Description
This is a matrix transformation problem where:
- We have a 3x3 matrix initially filled with white cells (represented as 1)
- Commands are given as letters corresponding to rows (D,E,F) or columns (A,B,C)
- Each command transforms the matrix according to specific rules
- The output should represent black cells as 0 and white cells as 1

# Visual Facts
1. The matrix is 3x3 with columns labeled A,B,C and rows labeled D,E,F
2. Cells can be either white or black
3. Each command is a single letter
4. Initial state is all white cells
5. The state changes after each command
6. The commands shown in sequence are: "B", "E", "C", "D", "B"
7. Each command affects multiple cells simultaneously

# Visual Patterns
1. Column Command Pattern (A,B,C):
   - When a column command is given, it inverts all cells in that column

2. Row Command Pattern (D,E,F):
   - When a row command is given, it inverts all cells in that row

3. Inversion Rules:
   - White cells become black and black cells become white when affected

4. Command Independence:
   - Each command operates on the current state of the matrix
   - Previous command results affect the starting state for the next command
   - The order of commands matters


# Solution
from typing import List

def solution(commands: List[str]) -> List[List[int]]:
    """
    Given a series of commands, transform the color of a matrix according to the rules shown in the image.

    Input:
    - command: A list of strings, where each string is a command that modifies the matrix.
               For example: ['A', 'B', 'E'].

    Output:
    - A 3x3 matrix of integers, where each integer represents the color of the cell in the matrix. 1 represents white, 0 represents black.
    """
    matrix = [[1] * 3 for _ in range(3)]

    for command in commands:
        if command == 'A':
            for i in range(3):
                matrix[i][0] = 1 - matrix[i][0]
        elif command == 'B':
            for i in range(3):
                matrix[i][1] = 1 - matrix[i][1]
        elif command == 'C':
            for i in range(3):
                matrix[i][2] = 1 - matrix[i][2]
        elif command == 'D':
            for j in range(3):
                matrix[0][j] = 1 - matrix[0][j]
        elif command == 'E':
            for j in range(3):
                matrix[1][j] = 1 - matrix[1][j]
        elif command == 'F':
            for j in range(3):
                matrix[2][j] = 1 - matrix[2][j]

    return matrix


# Test Script
def test():
    test_cases = [
        {
            'input': ['B'],
            'expected': [[1, 0, 1], [1, 0, 1], [1, 0, 1]]
        },
        {
            'input': ['E'],
            'expected': [[1, 1, 1], [0, 0, 0], [1, 1, 1]]
        },
        {
            'input': ['A'],
            'expected': [[0, 1, 1], [0, 1, 1], [0, 1, 1]]
        },
        {
            'input': ['C'],
            'expected': [[1, 1, 0], [1, 1, 0], [1, 1, 0]]
        },
        {
            'input': ['B', 'E'],
            'expected': [[1, 0, 1], [0, 1, 0], [1, 0, 1]]
        },
        {
            'input': ['A', 'C', 'F'],
            'expected': [[0, 1, 0], [0, 1, 0], [1, 0, 1]]
        },
        {
            'input': ['A', 'B', 'C', 'D', 'E', 'F'],
            'expected': [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
        },
        {
            'input': ['A', 'A'],
            'expected': [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
        },
        {
            'input': ['A', 'B', 'E', 'C', 'F'],
            'expected': [[0, 0, 0], [1, 1, 1], [1, 1, 1]]
        },
        {
            'input': ['A', 'B', 'E', 'F'],
            'expected': [[0, 0, 1], [1, 1, 0], [1, 1, 0]]
        }
    ]
    for test_case in test_cases:
        commands = test_case['input']
        expected_output = test_case['expected']
        
        try:
            output = solution(commands)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`commands`: {commands}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`commands`: {commands}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()