#include <bits/stdc++.h>
using namespace std;
char sa[3000], sb[3000], s[3000];
int fail[3000];
void makefail(char B[], int m) {
  fail[0] = -1;
  for (int i = 1, j = -1; i < m; i++) {
    while (j >= 0 && B[j + 1] != B[i]) j = fail[j];
    if (B[j + 1] == B[i]) j++;
    fail[i] = j;
  }
}
int cnt, cc;
int len;
void KMP(char A[], char B[], int n, int m) {
  for (int i = 0, j = 0; i < n; i++) {
    while (j > 0 && B[j] != A[i]) j = fail[j - 1] + 1;
    if (B[j] == A[i]) j++;
    if (j == m) {
      if (i > len - 1) {
        cnt++;
      }
      j = fail[j - 1] + 1;
    }
  }
}
int dp[105000][2];
int m;
void DP() {
  memset(dp, 0, sizeof(dp));
  if (strcmp(sa, sb) == 0) {
    dp[0][1] = 1;
  } else {
    dp[0][0] = 1;
  }
  for (int i = 0; i < m; i++) {
    if (dp[i][0]) {
      dp[i + 1][0] =
          ((long long)dp[i + 1][0] + (long long)dp[i][0] * (len - cnt - 1)) %
          1000000007ll;
      dp[i + 1][1] =
          ((long long)dp[i + 1][1] + (long long)dp[i][0] * cnt) % 1000000007ll;
    }
    if (dp[i][1]) {
      dp[i + 1][0] =
          ((long long)dp[i + 1][0] + (long long)dp[i][1] * (len - cnt)) %
          1000000007ll;
      dp[i + 1][1] =
          ((long long)dp[i + 1][1] + (long long)dp[i][1] * (cnt - 1)) %
          1000000007ll;
    }
  }
  printf("%d\n", dp[m][1]);
}
int main() {
  while (~scanf("%s%s", &sa, &sb)) {
    scanf("%d", &m);
    len = strlen(sa);
    makefail(sb, len);
    s[0] = 0;
    strcat(s, sa);
    strcat(s, sa);
    cnt = 0, cc = len;
    KMP(s, sb, 2 * len, len);
    DP();
  }
  return 0;
}
