#include <bits/stdc++.h>
using namespace std;
string s1, s2;
long long mod = 1000000007;
long long dp[100004][2];
int main() {
  int i, j, k, K;
  cin >> s1 >> s2 >> K;
  int sz = ((int)(s1).size());
  long long c = 0;
  for (i = (0); i <= (sz - 1); i++) {
    k = 0;
    for (j = (i); j <= (sz - 1); j++) {
      if (s1[j] != s2[k++]) break;
    }
    if (j != sz) continue;
    for (j = (0); j <= (i - 1); j++) {
      if (s1[j] != s2[k++]) break;
    }
    if (j == i) c++;
  }
  dp[0][0] = (s1 == s2);
  dp[0][1] = (s1 != s2);
  for (i = (1); i <= (K); i++) {
    dp[i][0] = dp[i - 1][0] * (c - 1) +
               dp[i - 1][1] * ((c) < (sz - 1) ? (c) : (sz - 1));
    dp[i][0] %= mod;
    dp[i][1] = dp[i - 1][0] * (sz - 1 - (c - 1)) +
               dp[i - 1][1] * ((0) > ((sz - 1 - c)) ? (0) : ((sz - 1 - c)));
    dp[i][1] %= mod;
  }
  cout << dp[K][0] << endl;
  return 0;
}
