#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, e;
  cin >> s >> e;
  int K;
  cin >> K;
  int N = s.size();
  int m[2][1001] = {0};
  m[0][0] = 1;
  int l = 1;
  long long sum0 = 1;
  long long sum1 = 0;
  long long sum = 1;
  for (int i = 1; i <= K; ++i) {
    sum0 = (sum - sum0 + 1000000007) % 1000000007;
    sum1 = (sum - sum1 + 1000000007) % 1000000007;
    sum = (sum0 + sum1 * (N - 1)) % 1000000007;
  }
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    string ne = s.substr(i, N - i) + s.substr(0, i);
    if (e == ne) {
      if (i == 0)
        ans = (ans + sum0) % 1000000007;
      else
        ans = (ans + sum1) % 1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}
