#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n, k;
string st, ed;
long long cnt_good;
long long dp[100005][2];
int main() {
  cin >> st >> ed >> k;
  n = st.size();
  cnt_good = 0;
  for (int i = 0; i < n; i++) {
    string shft = "";
    for (int j = i; j < n; j++) shft += st[j];
    for (int j = 0; j < i; j++) shft += st[j];
    if (shft == ed) cnt_good++;
  }
  long long cnt_bad = (long long)n - cnt_good;
  memset(dp, 0ll, sizeof(dp));
  if (st == ed)
    dp[0][1] = 1ll;
  else
    dp[0][0] = 1ll;
  for (int i = 1; i <= k; i++) {
    dp[i][0] = (dp[i - 1][0] * 1ll * (cnt_bad - 1ll)) % mod +
               (dp[i - 1][1] * 1ll * cnt_bad) % mod;
    dp[i][1] = (dp[i - 1][0] * 1ll * cnt_good) % mod +
               (dp[i - 1][1] * 1ll * (cnt_good - 1)) % mod;
    dp[i][0] %= mod;
    dp[i][1] %= mod;
  }
  cout << dp[k][1] << endl;
  return 0;
}
