#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
long long n, k, s, v, K, tmp, res;
string t1, t2, a[1010];
int i, j;
int main() {
  cin >> t1;
  cin >> t2;
  n = t1.size();
  cin >> K;
  for (j = 0; j < n; j++) {
    a[j] = t1;
    for (i = 0; i < j; i++) a[j][i + (n - j)] = t1[i];
    for (i = j; i < n; i++) a[j][i - j] = t1[i];
  }
  s = 1;
  for (k = 1; k <= K; k++) {
    tmp = s;
    s = (v * (n - 1LL)) % M;
    v = (v * (n - 2LL) + tmp) % M;
  }
  if (t1 == t2) res = s;
  for (i = 1; i < n; i++)
    if (t2 == a[i]) res = (res + v) % M;
  cout << res << endl;
}
