#!/usr/bin/env python3

MOD = 10**9 + 7
s = input()
n = int(input())

cnt = [0] * 26
ans = 0
for c in s:
    idx = ord(c) - ord('a')
    ans += sum(cnt[idx+1:])
    cnt[idx] += 1
ans *= n

mix = 0
for a in range(26):
    for b in range(a + 1, 26):
        mix += cnt[a] * cnt[b]
ans += mix * n * (n - 1) // 2
print(ans % MOD)
