S = input()
K = int(input())

# S単体で必要な置換数を求める
cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 0.5
    else:
        cnt = int(cnt+0.5)
cnt = int(cnt+0.5)

# Sを接続した時に必要な置換数を求める
s3 = S*3
cnt_1 = 0
for i in range(len(s3)-1):
    if s3[i] == s3[i+1]:
        cnt_1 += 0.5
    else:
        cnt_1 = int(cnt_1+0.5)
cnt_1 = int(cnt_1+0.5)

# 単体と接続時に必要な置換数の合計を求める
ans = int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K
print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input cnt = 0 cnt 0 for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 0.5
    else:
        cnt = int(cnt+0.5) i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i] == S[i+1]:
        cnt += 0.5
    else:
        cnt = int(cnt+0.5) S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 cnt += 0.5 cnt 0.5 cnt = int(cnt+0.5) cnt int(cnt+0.5) int cnt+0.5 cnt 0.5 cnt = int(cnt+0.5) cnt int(cnt+0.5) int cnt+0.5 cnt 0.5 s3 = S*3 s3 S*3 S 3 cnt_1 = 0 cnt_1 0 for i in range(len(s3)-1):
    if s3[i] == s3[i+1]:
        cnt_1 += 0.5
    else:
        cnt_1 = int(cnt_1+0.5) i range(len(s3)-1) range len(s3)-1 len(s3) len s3 1 if s3[i] == s3[i+1]:
        cnt_1 += 0.5
    else:
        cnt_1 = int(cnt_1+0.5) s3[i] == s3[i+1] s3[i] s3 i s3[i+1] s3 i+1 i 1 cnt_1 += 0.5 cnt_1 0.5 cnt_1 = int(cnt_1+0.5) cnt_1 int(cnt_1+0.5) int cnt_1+0.5 cnt_1 0.5 cnt_1 = int(cnt_1+0.5) cnt_1 int(cnt_1+0.5) int cnt_1+0.5 cnt_1 0.5 ans = int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K ans int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K int((cnt_1-cnt*3)/2*(K-1)+0.5) int (cnt_1-cnt*3)/2*(K-1)+0.5 (cnt_1-cnt*3)/2*(K-1) (cnt_1-cnt*3)/2 cnt_1-cnt*3 cnt_1 cnt*3 cnt 3 2 K-1 K 1 0.5 cnt*K cnt K print(ans) print ans cnt += 0.5 0.5 cnt cnt = int(cnt+0.5) int(cnt+0.5) cnt K = int(input()) int(input()) K cnt_1 = int(cnt_1+0.5) int(cnt_1+0.5) cnt_1 cnt_1 = 0 0 cnt_1 cnt_1 += 0.5 0.5 cnt_1 s3 = S*3 S*3 s3 ans = int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K ans cnt = 0 0 cnt cnt = int(cnt+0.5) int(cnt+0.5) cnt S = input() input() S cnt_1 = int(cnt_1+0.5) int(cnt_1+0.5) cnt_1
S = input()
K = int(input())

# S単体で必要な置換数を求める
cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 0.5
    else:
        cnt = int(cnt+0.5)
cnt = int(cnt+0.5)

# Sを接続した時に必要な置換数を求める
s3 = S*3
cnt_1 = 0
for i in range(len(s3)-1):
    if s3[i] == s3[i+1]:
        cnt_1 += 0.5
    else:
        cnt_1 = int(cnt_1+0.5)
cnt_1 = int(cnt_1+0.5)

# 単体と接続時に必要な置換数の合計を求める
ans = int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K
print(ans)
