#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  long long i, j, n, m, k;
  string s1, s2;
  cin >> s1 >> s2 >> k;
  n = s1.length();
  long long cnt = 0;
  long long temp = 1;
  for (i = 0; i < n; i++)
    if (s1[i] != s2[i]) temp = 0;
  for (i = 0; i < n; i++) {
    long long pos = 1;
    for (j = 0; j < n; j++)
      if (s2[j] != s1[(j + i) % n]) pos = 0;
    if (pos == 1) cnt++;
  }
  long long dp[k + 1][2];
  dp[0][0] = temp;
  dp[0][1] = temp ^ 1;
  for (i = 1; i <= k; i++)
    dp[i][0] = (dp[i - 1][1] * cnt + dp[i - 1][0] * (cnt - 1)) % 1000000007,
    dp[i][1] =
        (dp[i - 1][0] * (n - cnt) + dp[i - 1][1] * (n - 1 - cnt)) % 1000000007;
  cout << dp[k][0];
  return 0;
}
