#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5 + 5;
const long long P = 1e9 + 7;
int k, n, cnt;
char S[3005], T[3005];
long long f[N][2];
inline int check(int l, int r) {
  for (register int i = l; i <= r; ++i)
    if (S[i] != T[i - l + 1]) return 0;
  return 1;
}
int main() {
  scanf("%s%s%d", S + 1, T + 1, &k);
  n = strlen(S + 1);
  for (register int i = 1; i <= n; ++i) S[i + n] = S[i];
  for (register int i = 1; i <= n; ++i) cnt += check(i, i + n - 1);
  f[0][1 ^ check(1, n)] = 1;
  for (register int i = 1; i <= k; ++i) {
    f[i][0] = cnt * f[i - 1][1] % P + (cnt - 1) * (f[i - 1][0]) % P;
    f[i][0] %= P;
    f[i][1] = (n - cnt) * f[i - 1][0] % P + (n - cnt - 1) * (f[i - 1][1]) % P;
    f[i][1] %= P;
  }
  printf("%lld", f[k][0]);
}
