s = list(input())
k = int(input())

s2 = s + s
s3 = s + s + s

tmp = s[0]
c = 0
for i in range(1,len(s)):
    if s[i] == tmp:
        s[i] = "@"
        c += 1
    tmp = s[i] 

tmp = s2[0]
c2 = 0
for i in range(1,len(s2)):
    if s2[i] == tmp:
        s2[i] ="@"
        c2 += 1
    tmp = s2[i]

tmp = s3[0]
c3 = 0
for i in range(1,len(s3)):
    if s3[i] == tmp:
        s3[i] ="@"
        c3 += 1
    tmp = s3[i]

if c2-c == c3-c2:
    ans = c + (k-1)*(c2-c)
else:
    if k%2 != 0:
        ans = c + ((k-1)//2)*(c3-c)
    else:
        ans = c + ((k-2)//2)*(c3-c2) + c2 - c
print(ans) s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input s2 = s + s s2 s + s s s s3 = s + s + s s3 s + s + s s + s s s s tmp = s[0] tmp s[0] s 0 c = 0 c 0 for i in range(1,len(s)):
    if s[i] == tmp:
        s[i] = "@"
        c += 1
    tmp = s[i]  i range(1,len(s)) range 1 len(s) len s if s[i] == tmp:
        s[i] = "@"
        c += 1
     s[i] == tmp s[i] s i tmp s[i] = "@" s[i] s i "@" c += 1 c 1 tmp = s[i] tmp s[i] s i tmp = s2[0] tmp s2[0] s2 0 c2 = 0 c2 0 for i in range(1,len(s2)):
    if s2[i] == tmp:
        s2[i] ="@"
        c2 += 1
    tmp = s2[i] i range(1,len(s2)) range 1 len(s2) len s2 if s2[i] == tmp:
        s2[i] ="@"
        c2 += 1
     s2[i] == tmp s2[i] s2 i tmp s2[i] ="@" s2[i] s2 i "@" c2 += 1 c2 1 tmp = s2[i] tmp s2[i] s2 i tmp = s3[0] tmp s3[0] s3 0 c3 = 0 c3 0 for i in range(1,len(s3)):
    if s3[i] == tmp:
        s3[i] ="@"
        c3 += 1
    tmp = s3[i] i range(1,len(s3)) range 1 len(s3) len s3 if s3[i] == tmp:
        s3[i] ="@"
        c3 += 1
     s3[i] == tmp s3[i] s3 i tmp s3[i] ="@" s3[i] s3 i "@" c3 += 1 c3 1 tmp = s3[i] tmp s3[i] s3 i if c2-c == c3-c2:
    ans = c + (k-1)*(c2-c)
else:
    if k%2 != 0:
        ans = c + ((k-1)//2)*(c3-c)
    else:
        ans = c + ((k-2)//2)*(c3-c2) + c2 - c c2-c == c3-c2 c2-c c2 c c3-c2 c3 c2 ans = c + (k-1)*(c2-c) ans c + (k-1)*(c2-c) c (k-1)*(c2-c) k-1 k 1 c2-c c2 c if k%2 != 0:
        ans = c + ((k-1)//2)*(c3-c)
    else:
        ans = c + ((k-2)//2)*(c3-c2) + c2 - c k%2 != 0 k%2 k 2 0 ans = c + ((k-1)//2)*(c3-c) ans c + ((k-1)//2)*(c3-c) c ((k-1)//2)*(c3-c) (k-1)//2 k-1 k 1 2 c3-c c3 c ans = c + ((k-2)//2)*(c3-c2) + c2 - c ans c + ((k-2)//2)*(c3-c2) + c2 - c c + ((k-2)//2)*(c3-c2) + c2 c + ((k-2)//2)*(c3-c2) c ((k-2)//2)*(c3-c2) (k-2)//2 k-2 k 2 2 c3-c2 c3 c2 c2 c print(ans) print ans ans = c + (k-1)*(c2-c) c + (k-1)*(c2-c) ans tmp = s[i] s[i] tmp c += 1 1 c s3 = s + s + s s + s + s s3 k = int(input()) int(input()) k c2 += 1 1 c2 ans = c + ((k-2)//2)*(c3-c2) + c2 - c c + ((k-2)//2)*(c3-c2) + c2 - c ans tmp = s2[i] s2[i] tmp tmp = s3[0] s3[0] tmp tmp = s2[0] s2[0] tmp c = 0 0 c s2 = s + s s + s s2 c3 = 0 0 c3 c3 += 1 1 c3 tmp = s[0] s[0] tmp s = list(input()) list(input()) s ans = c + ((k-1)//2)*(c3-c) c + ((k-1)//2)*(c3-c) ans tmp = s3[i] s3[i] tmp c2 = 0 0 c2
s = list(input())
k = int(input())

s2 = s + s
s3 = s + s + s

tmp = s[0]
c = 0
for i in range(1,len(s)):
    if s[i] == tmp:
        s[i] = "@"
        c += 1
    tmp = s[i] 

tmp = s2[0]
c2 = 0
for i in range(1,len(s2)):
    if s2[i] == tmp:
        s2[i] ="@"
        c2 += 1
    tmp = s2[i]

tmp = s3[0]
c3 = 0
for i in range(1,len(s3)):
    if s3[i] == tmp:
        s3[i] ="@"
        c3 += 1
    tmp = s3[i]

if c2-c == c3-c2:
    ans = c + (k-1)*(c2-c)
else:
    if k%2 != 0:
        ans = c + ((k-1)//2)*(c3-c)
    else:
        ans = c + ((k-2)//2)*(c3-c2) + c2 - c
print(ans)
