#include <bits/stdc++.h>
const int maxn = 1010;
const int mod = 1000000007;
long long dp[100010][2];
char a[maxn << 1], b[maxn];
int main() {
  int k, x = 0;
  scanf("%s", a);
  scanf("%s", b);
  scanf("%d", &k);
  int len = strlen(a);
  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)) x++;
  }
  dp[0][strncmp(a, b, len) != 0] = 1;
  for (int i = 1; i <= k; i++) {
    dp[i][0] = dp[i - 1][0] * (x - 1) + dp[i - 1][1] * x;
    dp[i][0] %= mod;
    dp[i][1] = dp[i - 1][0] * (len - x) + dp[i - 1][1] * (len - x - 1);
    dp[i][1] %= mod;
  }
  printf("%I64d\n", dp[k][0]);
  return 0;
}
