#include <bits/stdc++.h>
using namespace std;
long long dp[2][100001];
int main() {
  ios_base::sync_with_stdio(0);
  string a, b;
  int k;
  cin >> a >> b >> k;
  int sz = a.size(), br1 = 0, br2 = 0;
  for (int i = 1; i < sz; i++) {
    if (a.substr(i) + a.substr(0, i) == b)
      br1++;
    else
      br2++;
  }
  if (a == b) {
    dp[0][0] = 1;
    br1++;
  } else {
    dp[1][0] = 1;
    br2++;
  }
  for (int i = 1; i <= k; i++) {
    dp[0][i] =
        dp[0][i - 1] * (br1 - 1) % 1000000007 + dp[1][i - 1] * br1 % 1000000007;
    dp[1][i] =
        dp[0][i - 1] * br2 % 1000000007 + dp[1][i - 1] * (br2 - 1) % 1000000007;
    dp[0][i] %= 1000000007;
    dp[1][i] %= 1000000007;
  }
  cout << dp[0][k] << endl;
  return 0;
}
