#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5, mod = 1e9 + 7, M = 1e5 + 10;
char s[N], t[N];
int k, n, A, B, fA[M], fB[M];
bool chk(int x) {
  for (int i = 1; i <= n; i++) {
    if (s[x] != t[i]) return 0;
    x = (x == n ? 1 : x + 1);
  }
  return 1;
}
int main() {
  scanf("%s%s%d", s + 1, t + 1, &k);
  n = strlen(s + 1);
  fA[0] = 0, fB[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (chk(i)) {
      if (i == 1) fA[0] = 1, fB[0] = 0;
      ++A;
    }
  }
  B = n - A;
  for (int i = 1; i <= k; i++) {
    fA[i] = (1ll * fA[i - 1] * (A - 1) % mod + 1ll * fB[i - 1] * A % mod) % mod;
    fB[i] = (1ll * fB[i - 1] * (B - 1) % mod + 1ll * fA[i - 1] * B % mod) % mod;
  }
  printf("%d\n", fA[k]);
  return 0;
}
