#include <bits/stdc++.h>
using namespace std;
const int M = 1002;
const long long MOD = 1000000007LL;
char b[M], a[M << 1];
int k;
long long dp[100004][2];
int main() {
  gets(a);
  gets(b);
  int m = strlen(a);
  strncpy(a + m, a, m);
  scanf("%d", &k);
  long long can = 0;
  for (int i = 0; i < m; i++)
    if (strncmp(a + i, b, m) == 0) can++;
  dp[0][strncmp(b, a, m) != 0] = 1;
  for (int i = 0; i < k; i++) {
    dp[i + 1][0] = (dp[i][0] * (can - 1) + dp[i][1] * can) % MOD;
    dp[i + 1][1] = (dp[i][1] * (m - can - 1) + dp[i][0] * (m - can)) % MOD;
  }
  printf("%I64d\n", dp[k][0]);
  return 0;
}
