#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
char st[N], en[N];
int cnt[333];
int can[N];
int n;
long long f(int i, int j) {
  if (j == 0) return can[i];
  long long ans = 0;
  for (int w = 0; w < n; w++)
    if (w != i) ans = (ans + f(w, j - 1)) % 1000000007;
  return ans;
}
long long dp[3][N];
int main() {
  int k;
  scanf(" %s %s %d", st, en, &k);
  n = strlen(st);
  for (int i = 0; i < n; i++) cnt[st[i]]++;
  for (int i = 0; i < n; i++) cnt[en[i]]--;
  for (int i = 0; i < 333; i++)
    if (cnt[i]) return printf("0\n"), 0;
  for (int i = 0; i < n; i++) st[n + i] = st[i];
  for (int i = 0; i < n; i++) can[i] = dp[0][i] = strncmp(en, st + i, n) == 0;
  long long tmp = 0;
  for (int i = 0; i < n; i++) tmp += dp[0][i];
  for (int j = 1; j < k + 1; j++) {
    for (int i = 0; i < n; i++) {
      dp[j & 1][i] = (tmp - dp[(j - 1) & 1][i] + 1000000007) % 1000000007;
    }
    tmp = (tmp * (n - 1)) % 1000000007;
  }
  printf("%lld\n", dp[k & 1][0]);
  return 0;
}
