#include <bits/stdc++.h>
using namespace std;
string s1, s2, s3;
char ct;
const long long mod = 1000000007;
long long T, l, a[2];
long long b[2];
long long res;
int main() {
  cin >> s1;
  cin >> s2;
  cin >> T;
  s3 = s1;
  l = s1.length();
  for (long long i = 1; i <= l; i++) {
    ct = s3[0];
    for (long long j = 0; j < l - 1; j++) {
      s3[j] = s3[j + 1];
    }
    s3[l - 1] = ct;
    if (s3 == s2) res++;
  }
  if (s1 == s2) a[1] = 1;
  a[0] = 1 - a[1];
  while (T--) {
    b[0] = (l - res) * a[1] + (l - res - 1) * a[0];
    b[1] = (res - 1) * a[1] + (res)*a[0];
    a[0] = b[0] % mod;
    a[1] = b[1] % mod;
  }
  cout << a[1] << endl;
  return 0;
}
