#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <class T>
bool ckmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
const int N = 1005;
const int K = 100005;
int n, k, dp[K][2], A, B;
char a[N], b[N];
bool check(int st) {
  for (int i = st, j = 0; j < n; (++i) %= n, ++j)
    if (a[i] != b[j]) return 0;
  return 1;
}
signed main() {
  scanf("%s%s%d", a, b, &k), n = strlen(a);
  for (int i = 0; i < n; ++i)
    if (check(i))
      ++A;
    else
      ++B;
  if (!A) return puts("0"), 0;
  if (check(0))
    dp[0][1] = 1;
  else
    dp[0][0] = 1;
  for (int i = 1, iend = k; i <= iend; ++i)
    dp[i][0] =
        (1ll * dp[i - 1][0] * (B - 1) + 1ll * dp[i - 1][1] * B) % 1000000007,
    dp[i][1] =
        (1ll * dp[i - 1][0] * A + 1ll * dp[i - 1][1] * (A - 1)) % 1000000007;
  cout << dp[k][1] << '\n';
}
