#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e3 + 7;
string s, e;
int all, k, n;
int dp[N][2];
void precalc() {
  for (int i = 0; i < n; ++i) {
    dp[i][k & 1] = (s.substr(i, n - i) + s.substr(0, i) == e);
    all += dp[i][k & 1];
  }
}
void solve() {
  cin >> s >> e >> k;
  if (k == 0) {
    cout << (s == e);
    return;
  }
  n = s.size();
  precalc();
  int it = 1;
  for (int j = k - 1; j > 0; --j) {
    int newAll = 0;
    it = j & 1;
    for (int i = 0; i < n; ++i) {
      dp[i][it] = (all - dp[i][!it] + mod) % mod;
      newAll = (newAll + dp[i][it]) % mod;
    }
    all = newAll;
  }
  cout << (all - dp[0][it] + mod) % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
