#include <bits/stdc++.h>
using namespace std;
char a[1005], b[1005];
const int oo = 1000000007;
int K;
long long n, m, cnt = 0, zero = 0;
int main() {
  scanf("%s", a);
  n = strlen(a);
  scanf("%s", b);
  m = strlen(b);
  scanf("%d", &K);
  if (n != m) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    int k = i, flag = 1;
    for (int j = 0; j < n; j++) {
      if (b[j] != a[k]) flag = 0;
      if (k < n - 1)
        k++;
      else
        k = 0;
    }
    if (flag)
      if (i)
        cnt++;
      else
        zero = 1;
  }
  long long f0 = 1, f1 = 0, f2, f3;
  for (int i = 1; i <= K; i++) {
    f2 = f1 * (n - 1) % oo;
    f3 = f1 * (n - 2) % oo + f0;
    f0 = f2;
    f1 = f3 % oo;
  }
  printf("%d\n", (f0 * zero + f1 * cnt) % oo);
  return 0;
}
