#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
string s1, s2, s3;
bool check[1005];
int main() {
  int n, k;
  cin >> s1 >> s2;
  n = s1.length();
  scanf("%d", &k);
  if (k == 0) {
    if (s1 != s2) {
      printf("0\n");
    } else {
      printf("1\n");
    }
    return 0;
  }
  for (int i = 0; i < n; i++) {
    s3 = "";
    for (int j = i; j < n; j++) {
      s3 += s1[j];
    }
    for (int j = 0; j < i; j++) {
      s3 += s1[j];
    }
    if (s2 == s3) check[i] = 1;
  }
  int f0 = 1, f1 = 0;
  for (int i = 1; i <= k; i++) {
    int tmp = f1;
    f1 = f0 % mod;
    f1 = (f1 + (long long)(n - 2) * tmp) % mod;
    f0 = (long long)tmp * (n - 1) % mod;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0 && check[i])
      ans = (ans + f0) % mod;
    else if (check[i])
      ans = (ans + f1) % mod;
  }
  printf("%d\n", ans);
}
