#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
string A, B, C;
long long ans[200000], biu[200000];
int main() {
  cin >> A >> B;
  int k;
  cin >> k;
  if (k == 0) {
    if (A == B)
      cout << 1 << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  int n = A.length();
  int can = 0;
  C = A + A;
  for (int i = 0; i < n; ++i)
    if (C.substr(i, n) == B) can++;
  biu[0] = 1;
  for (int i = 1; i <= 100000; ++i)
    biu[i] = biu[i - 1] * (n - 1), biu[i] %= mod;
  if (A == B)
    ans[1] = can - 1;
  else
    ans[1] = can;
  for (int i = 2; i <= k; ++i) {
    ans[i] = biu[i - 1] * can - ans[i - 1];
    ans[i] += mod;
    ans[i] %= mod;
  }
  cout << ans[k] << endl;
  return 0;
}
