#include <bits/stdc++.h>
using namespace std;
string s, t;
int n, k, amo;
int dp[200000][3];
int solve(int k, int ok) {
  if (!k) return ok;
  if (dp[k][ok] != -1) return dp[k][ok];
  dp[k][ok] = 0;
  long long res = 0;
  if (ok) {
    res += (1ll * solve(k - 1, 0) * (n - amo)) % 1000000007;
    res += (1ll * solve(k - 1, 1) * (amo - 1)) % 1000000007;
  } else {
    res += (1ll * solve(k - 1, 0) * (n - amo - 1)) % 1000000007;
    res += (1ll * solve(k - 1, 1) * (amo)) % 1000000007;
  }
  res %= 1000000007;
  return dp[k][ok] = res;
}
int main() {
  cin >> s >> t >> k;
  n = (int(s.size()));
  if (n == 1) {
    int res = 0;
    if (!k && s == t) res = 1;
    printf("%d\n", res);
    return 0;
  }
  if (k == 0) {
    int res = s == t;
    printf("%d\n", res);
    return 0;
  }
  amo = s == t;
  for (int i = 1; i < n; i++) {
    if (s.substr(i) + s.substr(0, i) == t) amo++;
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(k, s == t) << endl;
  return 0;
}
