#include <bits/stdc++.h>
const int N = 2222;
char a[N], b[N];
long long dp[111111][2];
int main(void) {
  int k, x = 0, len;
  scanf("%s%s", a, b);
  scanf("%d", &k);
  len = strlen(a);
  dp[0][strcmp(a, b) != 0] = 1;
  for (int i = 0; i < len; i++) a[i + len] = a[i];
  for (int i = 0; i < len; i++)
    if (strncmp(a + i, b, len) == 0) x++;
  for (int i = 0; i < k; i++) {
    dp[i + 1][0] = (x * dp[i][1] + (x - 1) * dp[i][0]) % 1000000007;
    dp[i + 1][1] =
        ((len - x) * dp[i][0] + (len - x - 1) * dp[i][1]) % 1000000007;
  }
  printf("%I64d\n", dp[k][0]);
  return 0;
}
