def season_to_month_tuple(seasons: Sequence[str]) -> tuple[tuple[int, ...], ...]:
    """
    >>> season_to_month_tuple(["DJF", "MAM", "JJA", "SON"])
    ((12, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11))
    >>> season_to_month_tuple(["DJFM", "MAMJ", "JJAS", "SOND"])
    ((12, 1, 2, 3), (3, 4, 5, 6), (6, 7, 8, 9), (9, 10, 11, 12))
    >>> season_to_month_tuple(["DJFM", "SOND"])
    ((12, 1, 2, 3), (9, 10, 11, 12))
    """
    initials = "JFMAMJJASOND"
    starts = dict(
        ("".join(s), i + 1)
        for s, i in zip(sliding_window(2, initials + "J"), range(12), strict=True)
    )
    result: list[tuple[int, ...]] = []
    for i, season in enumerate(seasons):
        if len(season) == 1:
            if i < len(seasons) - 1:
                suffix = seasons[i + 1][0]
            else:
                suffix = seasons[0][0]
        else:
            suffix = season[1]

        start = starts[season[0] + suffix]

        month_append = []
        for i in range(len(season[1:])):
            elem = start + i + 1
            month_append.append(elem - 12 * (elem > 12))
        result.append((start,) + tuple(month_append))
    return tuple(result)

    >>> season_to_month_tuple(["DJF", "MAM", "JJA", "SON"])
    ((12, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11))
    >>> season_to_month_tuple(["DJFM", "MAMJ", "JJAS", "SOND"])
    ((12, 1, 2, 3), (3, 4, 5, 6), (6, 7, 8, 9), (9, 10, 11, 12))
    >>> season_to_month_tuple(["DJFM", "SOND"])
    ((12, 1, 2, 3), (9, 10, 11, 12))
    
xarray/groupers.py