def is_prim_rou(modulus: int, degree: int, val: int) -> bool:
    """
    Test whether input x is a primitive 2d^th root of unity in the integers modulo q. Does not require q and d to be
    NTT-friendly pair.

    :param modulus: Input modulus
    :type modulus: int
    :param degree: Input degree
    :type degree: int
    :param val: Purported root of unity
    :type val: int

    :return: Boolean indicating x**(2d) == 1 and x**i != 1 for 1 <= i < 2d.
    :rtype: bool
    """
    return all(val ** k % modulus != 1 for k in range(1, 2 * degree)) and val ** (2 * degree) % modulus == 1