#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
long long dp[N][2];
void solve() {
  memset(dp, 0, sizeof(dp));
  string a, b;
  cin >> a >> b;
  (a == b ? dp[0][1] = 1 : dp[0][0] = 1);
  int k;
  cin >> k;
  long long way_good = 0, way_bad = 0;
  string s = a;
  for (int i = 0; i < (int)(a).size(); i++) {
    (s == b ? ++way_good : ++way_bad);
    s = a.substr(i + 1, (int)(a).size() - i) + a.substr(0, i + 1);
  }
  for (int i = 1; i <= k; i++) {
    dp[i][1] = (((dp[i - 1][1] * (way_good - 1)) % MOD) +
                (dp[i - 1][0] * (way_good)) % MOD) %
               MOD;
    dp[i][0] = (((dp[i - 1][1] * (way_bad)) % MOD) +
                (dp[i - 1][0] * (way_bad - 1)) % MOD) %
               MOD;
  }
  cout << dp[k][1] % MOD << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  solve();
  return 0;
}
