#include <bits/stdc++.h>
using namespace std;
char s1[1024], s2[1024];
int L;
const int MOD = 1000000007;
int powm(long long int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return ret;
}
int table[100009][2];
int main() {
  int K;
  scanf("%s%s%d", s1, s2, &K);
  L = strlen(s1);
  int alc = 0;
  for (int i = 1; i < L; i++)
    if (!strncmp(s1 + i, s2, L - i) && !strncmp(s1, s2 + L - i, i)) alc++;
  if (K == 0)
    printf("%d\n", (int)(!strcmp(s1, s2)));
  else {
    table[0][0] = 0;
    table[0][1] = 1;
    for (int i = 1; i <= K; i++) {
      table[i][0] = table[i - 1][1];
      table[i][1] = (table[i - 1][0] * (long long int)(L - 1) % MOD +
                     table[i - 1][1] * (long long int)(L - 2) % MOD) %
                    MOD;
    }
    int ans = table[K][0] * (long long int)alc % MOD;
    table[0][0] = 1;
    table[0][1] = 0;
    for (int i = 1; i <= K; i++) {
      table[i][0] = table[i - 1][1];
      table[i][1] = (table[i - 1][0] * (long long int)(L - 1) % MOD +
                     table[i - 1][1] * (long long int)(L - 2) % MOD) %
                    MOD;
    }
    if (!strcmp(s1, s2)) ans = (ans + table[K][0]) % MOD;
    printf("%d\n", ans);
  }
  return 0;
}
