#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007ll;
char s[2222], t[1111];
int N, K;
long long f[111111][2];
int main() {
  int i, j, k;
  memset(s, 0, sizeof s);
  cin >> s >> t >> K;
  N = strlen(s);
  f[0][0] = 1;
  f[0][1] = 0;
  for (i = 1; i <= K; ++i) {
    f[i][0] = f[i - 1][1] * (N - 1) % mod;
    f[i][1] = (f[i - 1][0] + f[i - 1][1] * (N - 2)) % mod;
  }
  long long ans = 0;
  for (i = 0; i < N; ++i) {
    if (strcmp(s + i, t) == 0) ans = (ans + f[K][i ? 1 : 0]) % mod;
    s[N + i] = s[i];
  }
  cout << ans % mod << '\n';
  return 0;
}
