import io


def parse(stdin: io.TextIOWrapper) -> list:
    """
    Parse the input into a list of tuples, each with a little-endian bit mask
    represented as a list and a list of commands to execute.
    """

    return list(map(
        lambda chunk: (
            {
                35 - k: v
                for k, v in enumerate([
                    int(char) if char != 'X' else None
                    for char in chunk[0]
                ])
            },
            [
                tuple(map(int, command.replace("mem[", "").split("] = ", 1)))
                for command in chunk[1].strip().split("\n")
            ]
        ),
        [
            (chunk.split("\n", 1))
            for chunk in stdin.read().strip().split("mask = ") if chunk != ""
        ]
    ))