#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  int t = 1;
  while (t--) solve();
  return 0;
}
int dp[2][1010];
int sum[101010];
const int mod = 1000000007;
void solve() {
  string s, e;
  cin >> s >> e;
  int k;
  cin >> k;
  int n = s.size();
  dp[0][0] = 1;
  sum[0] = 1;
  for (int len = 1; len <= k; ++len) {
    for (int j = 0; j < n; ++j) {
      dp[len % 2][j] = (sum[len - 1] - dp[(len - 1) % 2][j] + mod) % mod;
      sum[len] += dp[len % 2][j];
      sum[len] %= mod;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    bool ok = true;
    for (int j = 0; j < n; ++j) {
      if (e[(i + j) % n] != s[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans += dp[k % 2][i];
      ans %= mod;
    }
  }
  cout << ans;
}
