#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
const long long MOD = 1e9 + 7;
long long ans = 0, dpg[N * 100], dpb[100 * N];
char st[2 * N], en[N];
int main() {
  int n, k;
  scanf("%s", st);
  scanf("%s", en);
  scanf("%d", &k);
  n = strlen(st);
  int t = 0;
  bool stst = false;
  for (int i = 0; i < n; i++) {
    int j1 = i, j2 = 0;
    while (j2 < n) {
      if (st[j1 % n] != en[j2]) break;
      j1++;
      j2++;
    }
    if (j2 == n) {
      t++;
      if (i == 0) stst = true;
    }
  }
  if (t > 0) {
    dpg[0] = stst;
    dpb[0] = 1 - stst;
    for (int i = 1; i <= k; i++) {
      dpg[i] = dpg[i - 1] * (t - 1) + dpb[i - 1] * t;
      dpg[i] %= MOD;
      dpb[i] = dpb[i - 1] * (n - t - 1) + dpg[i - 1] * (n - t);
      dpb[i] %= MOD;
    }
    printf("%I64d\n", dpg[k]);
  } else
    printf("0\n");
  return 0;
}
