#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int maxn = 1000 * 100 + 100;
long long dp1[maxn], dp2[maxn];
int main() {
  long long k, ok = 0, no = 0;
  string a, b;
  cin >> a >> b >> k;
  for (int i = 0; i < a.size(); i++) {
    string s = a.substr(i, a.size() - i);
    s += a.substr(0, i);
    if (s == b)
      ok++;
    else
      no++;
  }
  if (a == b) {
    dp1[0] = 1;
  } else {
    dp2[0] = 1;
  }
  for (int i = 1; i <= k; i++) {
    dp1[i] = ((dp1[i - 1] * (ok - 1)) % mod + (dp2[i - 1] * (ok)) % mod) % mod;
    dp2[i] = ((dp1[i - 1] * (no)) % mod + (dp2[i - 1] * (no - 1)) % mod) % mod;
  }
  cout << dp1[k] << endl;
  return 0;
}
