#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010, MAXK = 100100, MOD = 1000000007;
int dp[MAXK][2];
char a[2 * MAXN], b[MAXN];
int main(void) {
  int n, m;
  scanf("%s%s%d", a, b, &m);
  n = strlen(a);
  dp[0][0] = 1;
  for (int i = 1; i <= m; ++i) {
    dp[i][0] = ((long long)dp[i - 1][1] * (n - 1)) % MOD;
    dp[i][1] = ((long long)dp[i - 1][1] * (n - 2) + dp[i - 1][0]) % MOD;
  }
  for (int i = n; i < 2 * n; ++i) {
    a[i] = a[i - n];
  }
  int cnt = 0, z = 0;
  for (int i = 0; i < (n); ++i) {
    if (strncmp(a + i, b, n) == 0) {
      if (i == 0) {
        ++z;
      } else {
        ++cnt;
      }
    }
  }
  int res = ((long long)dp[m][0] * z + (long long)dp[m][1] * cnt) % MOD;
  printf("%d\n", res);
  return 0;
}
