L = int(input())
S = input()
ACC = 1
MOD = 1234567891
ans = 0
for c in S:
    v = ord(c) - 96
    ans = (ans + (v * ACC)) % MOD
    ACC *= 31

print(ans)
    
73195d9b386881135621c6cf91642f87d6784256
<mask token>

<mask token>
for c in S:
    v = ord(c) - 96
    ans = (ans + v * ACC) % MOD
    ACC *= 31
print(ans)

L = int(input())
S = input()
ACC = 1
MOD = 1234567891
ans = 0
for c in S:
    v = ord(c) - 96
    ans = (ans + v * ACC) % MOD
    ACC *= 31
print(ans)

L = int(input())
S = input()
ACC = 1
MOD = 1234567891
ans = 0
for c in S:
    v = ord(c) - 96
    ans = (ans + (v * ACC)) % MOD
    ACC *= 31

print(ans)
    