#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int k;
string s, t;
int dp[100005][2], cnt[2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s >> t;
  cin >> k;
  int n = s.length();
  for (int i = 1; i < n; i++) {
    int l = n - i;
    string tmp = s.substr(i, l) + s.substr(0, i);
    if (tmp == t)
      cnt[0]++;
    else
      cnt[1]++;
  }
  if (s == t)
    dp[0][0]++, cnt[0]++;
  else
    dp[0][1]++, cnt[1]++;
  for (int i = 1; i <= k; i++) {
    dp[i][0] =
        (dp[i - 1][0] * 1ll * (cnt[0] - 1) + dp[i - 1][1] * 1ll * cnt[0]) % mod;
    dp[i][1] =
        (dp[i - 1][0] * 1ll * cnt[1] + dp[i - 1][1] * 1ll * (cnt[1] - 1)) % mod;
  }
  printf("%d\n", dp[k][0]);
}
