#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T begin, T end) {
  for (T i = begin; i != end; ++i) cout << *i << " ";
  cout << endl;
}
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int main() {
  string start, end;
  int K;
  while (cin >> start >> end >> K) {
    int N = start.size();
    vector<int> dp(N + 1);
    dp[0] = 1;
    long long sum = 1;
    for (int i = (0); i < (int)K; ++i) {
      long long nextsum = 0;
      vector<int> nextdp(N + 1);
      for (int j = (0); j < (int)N; ++j) {
        nextsum += (nextdp[j] = (sum - dp[j]) % MOD);
      }
      sum = nextsum;
      dp = nextdp;
    }
    int ans = 0;
    for (int i = (0); i < (int)N; ++i) {
      if (start.substr(i) + start.substr(0, i) == end) {
        ans += dp[i];
        ans %= MOD;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
