#include <bits/stdc++.h>
using namespace std;
long long dp[3][3];
int main() {
  int cnt, len, len2, i, func, same, diff, last, now;
  char b[3005], e[1005];
  while (scanf("%s%s", b, e) != EOF) {
    scanf("%d", &func);
    len = strlen(b);
    len2 = strlen(e);
    if (len != len2) {
      printf("0\n");
      continue;
    }
    cnt = 0;
    if (!strcmp(b, e)) {
      dp[0][0] = 1;
      dp[0][1] = 0;
    } else {
      dp[0][1] = 1;
      dp[0][0] = 0;
    }
    for (i = 0; i < len; i++) {
      b[len + i] = b[i];
      if (!strncmp(b + i, e, len)) cnt++;
    }
    same = cnt;
    diff = len - cnt;
    last = 0;
    now = 1;
    for (i = 0; i < func; i++) {
      dp[now][0] = dp[last][0] * (same - 1) + dp[last][1] * same;
      dp[now][1] = dp[last][1] * (diff - 1) + dp[last][0] * diff;
      dp[now][0] %= 1000000007;
      dp[now][1] %= 1000000007;
      last = now;
      now = !now;
    }
    printf("%lld\n", dp[last][0]);
  }
  return 0;
}
