#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
char s1[1100];
char s2[1100];
long long f[3][3];
int len1, len2, k;
int main() {
  scanf("%s", s1);
  scanf("%s", s2);
  scanf("%d", &k);
  len1 = strlen(s1);
  len2 = strlen(s2);
  if (len1 != len2) {
    printf("0\n");
    return 0;
  }
  f[0][0] = 1;
  for (int i = 1; i <= k; i++) {
    f[i % 2][0] = (f[(i - 1) % 2][1] % mod * (len1 - 1) % mod) % mod;
    f[i % 2][1] = (f[(i - 1) % 2][0] % mod +
                   (f[(i - 1) % 2][1] % mod * (len1 - 2) % mod) % mod) %
                  mod;
  }
  long long ans = 0, ok;
  for (int i = 0; i < len1; i++) {
    ok = 1;
    for (int j = 0; j < len1; j++) {
      if (s1[(i + j) % len1] != s2[j]) {
        ok = 0;
        break;
      }
    }
    if (ok)
      if (i == 0)
        ans = (ans % mod + f[k % 2][0] % mod) % mod;
      else
        ans = (ans % mod + f[k % 2][1] % mod) % mod;
    ans %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}
