def _poly_hash(text, prime, x):
    """
    Function for generating hash value from text

    Args:
        text: simple text
        prime: prime number to get modulo of
        x: random number between 1 and prime

    Returns:
        hash value of text
    """

    ans = 0
    for c in reversed(text):
        ans = (ans * x + ord(c)) % prime
    return ans