#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void read(int &k) {
  k = 0;
  char x = getchar();
  while (x < '0' || x > '9') x = getchar();
  while (x >= '0' && x <= '9') {
    k = k * 10 - 48 + x;
    x = getchar();
  }
}
char s0[4010], s1[4010];
int n, sum[100010], A0, A1, l, ans;
int solve(long long k) {
  for (int i = 1; i <= n; i++) k = (sum[i - 1] - k + MOD) % MOD;
  return int(k);
}
int main() {
  scanf("%s%s%d", s0, s1, &n);
  l = strlen(s0);
  for (int i = 0; i < l; i++) s1[i + l] = s1[i];
  sum[0] = 1;
  for (int i = 1; i <= n; i++) sum[i] = (l - 1ll) * sum[i - 1] % MOD;
  A0 = solve(0);
  A1 = solve(1);
  for (int i = 0, j; i < l; i++) {
    for (j = 0; j < l; j++)
      if (s1[i + j] != s0[j]) break;
    if (j == l)
      if (!i)
        ans = (ans + A1) % MOD;
      else
        ans = (ans + A0) % MOD;
  }
  cout << ans << endl;
  return 0;
}
