import io


def parse(stdin: io.TextIOWrapper) -> list:
    """
    Parse the input into a list of tuples, the first element being a set of
    allergens and the second a set of ingredients
    """

    result = list()
    for line in stdin.read().strip().splitlines():
        ingredients, allergens = line.strip(")").split(" (contains ")
        result.append((set(allergens.split(", ")), set(ingredients.split())))

    return result