#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main() {
  ios::sync_with_stdio(false);
  long long int MOD = 1000000007LL;
  string start, end;
  int k;
  while (cin >> start >> end >> k) {
    const int N = static_cast<int>(start.size());
    pair<long long int, long long int> dp(make_pair(1LL, 0LL));
    for (int i = 0; i < k; ++i) {
      pair<long long int, long long int> next;
      next.first = (dp.second * (N - 1)) % MOD;
      next.second = (dp.first + dp.second * (N - 2)) % MOD;
      swap(dp, next);
    }
    long long int ans = 0LL;
    if (start == end) ans += dp.first;
    for (int i = 1; i < N; ++i) {
      if (start.substr(i) + start.substr(0, i) == end) {
        ans += dp.second;
        ans %= MOD;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
