#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
int p[2];
long long dp[100000 + 1][2];
int main() {
  string s, e;
  cin >> s >> e;
  int n = s.length();
  for (int i = 0; i < n; ++i) {
    rotate(s.begin(), s.begin() + 1, s.end());
    ++p[s != e];
  }
  ++dp[0][s != e];
  int k;
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    dp[i][0] = (dp[i - 1][0] * (p[0] - 1) + dp[i - 1][1] * p[0]) % MOD;
    dp[i][1] = (dp[i - 1][0] * p[1] + dp[i - 1][1] * (p[1] - 1)) % MOD;
  }
  cout << dp[k][0];
  return 0;
}
