#include <bits/stdc++.h>
using namespace std;
long long K, N;
string A, B;
bool valid[1001];
long long dp[100002][2];
int main() {
  ios::sync_with_stdio(0);
  cin >> A >> B >> K;
  N = A.size();
  dp[0][0] = 1, dp[0][1] = 0;
  for (int i = 1; i <= K; ++i) {
    dp[i][0] = (N - 1) * dp[i - 1][1];
    dp[i][1] = dp[i - 1][0] + (N - 2) * dp[i - 1][1];
    dp[i][0] %= 1000000007;
    dp[i][1] %= 1000000007;
  }
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    valid[i] = true;
    for (int j = 0; j < N; ++j)
      if (A[j % N] != B[(i + j) % N]) valid[i] = false;
    if (valid[i]) {
      if (i == 0)
        ans = (ans + dp[K][0]) % 1000000007;
      else
        ans = (ans + dp[K][1]) % 1000000007;
    }
  }
  cout << ans << endl;
}
