#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int n, k;
long long f[100009], g[100009];
vector<int> p;
string s1, s2;
int main() {
  cin >> s1 >> s2 >> k;
  int i;
  n = s1.size();
  p.clear();
  for (i = 1; i <= n; ++i) {
    if (s1 == s2) p.push_back(i - 1);
    s1.push_back(s1[0]);
    s1.erase(0, 1);
  }
  f[0] = 1LL;
  g[0] = 0LL;
  for (i = 1; i <= k; ++i) {
    f[i] = (g[i - 1] * (n - 1)) % MOD;
    g[i] = (f[i - 1] + g[i - 1] * (n - 2)) % MOD;
  }
  long long ans = 0LL;
  if (!p.empty()) {
    for (i = 0; i < p.size(); ++i) {
      if (p[i] == 0)
        ans = (ans + f[k]) % MOD;
      else
        ans = (ans + g[k]) % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
