#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
int a, b, c, d, i, j, n, m, k;
char s1[1002], s2[1002], tmp[1002];
int f[100002][2];
int main() {
  scanf("%s%s", s1, s2);
  scanf("%d", &k);
  n = (int)strlen(s1);
  memcpy(tmp, s1, n);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    if (strcmp(tmp, s2) == 0) ++c;
    rotate(tmp, tmp + 1, tmp + n);
  }
  a = 0;
  if (strcmp(s1, s2) == 0) a = 1;
  f[0][a] = 1;
  for (int _n((k)), i(1); i <= _n; i++) {
    f[i][0] = ((long long)f[i - 1][0] * (n - c - 1) +
               (long long)f[i - 1][1] * (n - c)) %
              1000000007;
    f[i][1] = ((long long)f[i - 1][0] * c + (long long)f[i - 1][1] * (c - 1)) %
              1000000007;
  }
  printf("%d\n", f[k][1]);
}
