def sf_mag(a: tuple) -> int:
    """
    Calculates the magnitude of a snailfish number
    :param a: a snailfish number
    :return: the magnitude as int

    >>> sf_mag((9, 1))
    29

    >>> sf_mag((1, 9))
    21

    >>> sf_mag(((9, 1),(1, 9)))
    129

    >>> sf_mag(((1,2),((3,4),5)))
    143

    >>> sf_mag(((((0,7),4),((7,8),(6,0))),(8,1)))
    1384

    >>> sf_mag(((((1,1),(2,2)),(3,3)),(4,4)))
    445

    >>> sf_mag(((((3,0),(5,3)),(4,4)),(5,5)))
    791

    >>> sf_mag(((((5,0),(7,4)),(5,5)),(6,6)))
    1137

    >>> sf_mag(((((8,7),(7,7)),((8,6),(7,7))),(((0,7),(6,6)),(8,7))))
    3488

    >>> sf_mag(((((6,6),(7,6)),((7,7),(7,0))),(((7,7),(7,7)),((7,8),(9,9)))))
    4140
    """
    if type(a[0]) is int:
        left = a[0]
    else:
        left = sf_mag(a[0])
    if type(a[1]) is int:
        right = a[1]
    else:
        right = sf_mag(a[1])
    return left * 3 + right * 2