#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[1100000][2];
signed main() {
  string a, b;
  long long siz, n, ans_0 = 0, ans_1 = 0;
  cin >> a >> b >> n;
  if (a == b) ans_0++;
  siz = a.size();
  for (long long i = 1; i < siz; i++) {
    a = a[siz - 1] + a;
    a.erase(siz, 1);
    if (a == b) ans_1++;
  }
  dp[1][0] = 0, dp[1][1] = 1;
  for (long long i = 2; i <= n; i++) {
    dp[i][1] = (dp[i - 1][1] * (siz - 2) + dp[i - 1][0]) % MOD;
    dp[i][0] = dp[i - 1][1] * (siz - 1);
  }
  dp[0][0] = 1;
  long long ans = dp[n][0] * ans_0;
  for (long long i = 1; i <= ans_1; i++) {
    ans += dp[n][1];
    ans %= MOD;
  }
  cout << ans % MOD << endl;
  return 0;
}
