#include <bits/stdc++.h>
using namespace std;
long long n, g, b, dp[200005][2], m;
string s, s1, k;
long long MOD = 1e9 + 7;
char c;
int main() {
  cin >> s >> s1;
  k = s;
  cin >> m;
  n = s.size();
  for (int i = 0; i < n; i++) {
    c = s[n - 1];
    s.replace(n - 1, 1, "");
    s = c + s;
    if (s == s1) {
      g++;
    } else
      b++;
  }
  if (k == s1) {
    dp[0][0] = 1;
  } else
    dp[0][1] = 1;
  for (int i = 1; i <= m; i++) {
    dp[i][0] = (dp[i - 1][0] * (g - 1) % MOD + dp[i - 1][1] * g % MOD) % MOD;
    dp[i][1] = (dp[i - 1][0] * b % MOD + dp[i - 1][1] * (b - 1) % MOD) % MOD;
  }
  cout << dp[m][0] << endl;
}
