#include <bits/stdc++.h>
using namespace std;
char s1[1024], s2[1024];
int k, n;
int PD[100010][2];
int calc(int k, int x) {
  if (k == 1) return x;
  if (PD[k][x] != -1) return PD[k][x];
  long long int tot;
  if (x == 0)
    tot =
        ((long long int)(n - 1) * (long long int)calc(k - 1, 1)) % 1000000007ll;
  else
    tot = ((long long int)calc(k - 1, 0) +
           (long long int)(n - 2) * (long long int)calc(k - 1, 1)) %
          1000000007ll;
  return PD[k][x] = (int)tot;
}
inline bool igual(int ini2) {
  for (int i = ini2, c = 0; c < n; i++, c++) {
    if (i >= n) i -= n;
    if (s2[i] != s1[c]) return false;
  }
  return true;
}
int main() {
  scanf("%s %s %d", s1, s2, &k);
  n = strlen(s1);
  if (k == 0) {
    if (!strcmp(s1, s2))
      printf("1\n");
    else
      printf("0\n");
    return 0;
  }
  memset(PD, 0xff, sizeof(PD));
  int tot = 0;
  for (int i = 0; i < n; i++) {
    if (igual(i)) tot = (tot + calc(k, i ? 1 : 0)) % 1000000007ll;
  }
  printf("%d\n", tot);
  return 0;
}
