#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long k, n;
  string second, t;
  cin >> second >> t >> k;
  n = second.length();
  long long rots = 0;
  for (long long i = 0; i < n; i++) {
    bool flg = true;
    for (long long j = 0; j < n; j++) {
      if (second[(i + j) % n] != t[j]) {
        flg = false;
        break;
      }
    }
    if (flg) rots++;
  }
  long long dp[2][k + 1];
  if (second == t) {
    dp[0][0] = 1;
    dp[1][0] = 0;
  } else {
    dp[0][0] = 0;
    dp[1][0] = 1;
  }
  for (long long i = 1; i <= k; i++) {
    dp[0][i] = (dp[0][i - 1] * (rots - 1) + dp[1][i - 1] * (rots)) % 1000000007;
    dp[1][i] = (dp[0][i - 1] * (n - rots) + dp[1][i - 1] * (n - rots - 1)) %
               1000000007;
  }
  cout << dp[0][k];
  return 0;
}
