#include <bits/stdc++.h>
using namespace std;
int main() {
  long long dp[100001], dp2[100001];
  long long n;
  string a, b;
  long long match, k;
  cin >> a >> b >> k;
  string a2 = a;
  n = a.length();
  a = a + a.substr(0, n - 1);
  match = 0;
  for (int i = 0; i <= 2 * n - 2; i++) {
    if (a.substr(i, n) == b) match++;
  }
  dp[0] = dp2[0] = 0;
  dp[1] = match;
  dp2[1] = n - match - 1;
  if (a2 == b) {
    dp[1] = match - 1;
    dp2[1] = n - match;
    dp[0] = 1;
  }
  for (int i = 2; i <= k; i++) {
    dp[i] = ((dp[i - 1] * (match - 1)) % 1000000007 +
             (dp2[i - 1] * match) % 1000000007) %
            1000000007;
    dp2[i] = ((dp[i - 1] * (n - match)) % 1000000007 +
              (dp2[i - 1] * (n - match - 1)) % 1000000007) %
             1000000007;
  }
  cout << (dp[k]) << endl;
  return 0;
}
