#include <bits/stdc++.h>
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
inline long long read() {
  long long num = 0, f = 1;
  char c = getchar();
  while (c < 48 || c > 57) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c > 47 && c < 58) num = num * 10 + (c ^ 48), c = getchar();
  return num * f;
}
inline long long re1d() {
  char c = getchar();
  while (c < 48 || c > 49) c = getchar();
  return c & 1;
}
inline long long min(long long a, long long b) { return a > b ? b : a; }
inline long long max(long long a, long long b) { return a < b ? b : a; }
char a[500005], b[500005];
long long dp[500005][2];
long long cmp(long long l, long long r) {
  for (long long i = l, j = 0; i < r; i++, j++)
    if (a[i] != b[j]) return 0;
  return 1;
}
const long long mod = 1000000007;
signed main() {
  scanf("%s%s", a, b);
  long long n = strlen(a), k = 0, t = read();
  for (long long i = 0; i < n; i++) a[i + n] = a[i];
  for (long long i = 0; i < n; i++) k += cmp(i, i + n);
  dp[0][cmp(0, n) ^ 1] = 1;
  for (long long i = 1; i <= t; i++) {
    dp[i][0] = (dp[i - 1][1] * k + dp[i - 1][0] * (k - 1)) % mod;
    dp[i][1] = (dp[i - 1][0] * (n - k) + dp[i - 1][1] * (n - k - 1)) % mod;
  }
  printf("%lld\n", dp[t][0]);
}
