#include <bits/stdc++.h>
using namespace std;
const int N = 100010, mod = 1000000007;
long long n, k, cnt, f[N], g[N];
char s[N], t[N];
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
bool check(int l, int r) {
  int j = 0;
  for (int i = l; i <= r; i++) {
    if (s[i] != t[++j]) return 0;
  }
  return 1;
}
int main() {
  scanf("%s%s", s + 1, t + 1);
  k = read();
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    s[i + n] = s[i];
  }
  for (int i = 1; i <= n; i++) {
    if (check(i, i + n - 1)) cnt++;
  }
  if (check(1, n)) {
    f[0] = 1;
  } else
    g[0] = 1;
  for (int i = 1; i <= k; i++) {
    f[i] = (cnt * g[i - 1] % mod + (cnt - 1) * (f[i - 1]) % mod) % mod;
    g[i] = ((n - cnt) * f[i - 1] % mod + (n - cnt - 1) * g[i - 1] % mod) % mod;
  }
  printf("%lld", f[k]);
}
