#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int N, K;
long long F[100009], G[100009];
vector<int> p;
string S1, S2;
int main() {
  cin >> S1 >> S2;
  N = S1.size();
  p.clear();
  cin >> K;
  for (int i = 1; i <= N; i++) {
    if (S1 == S2) p.push_back(i - 1);
    S1.push_back(S1[0]);
    S1.erase(0, 1);
  }
  F[0] = 1LL, G[0] = 0LL;
  for (int i = 1; i <= K; i++) {
    F[i] = (G[i - 1] * (N - 1)) % MOD;
    G[i] = (F[i - 1] + G[i - 1] * (N - 2)) % MOD;
  }
  long long Ans = 0LL;
  if (!p.empty()) {
    for (int i = 0; i <= p.size() - 1; i++) {
      if (p[i] == 0)
        Ans = (Ans + F[K]) % MOD;
      else
        Ans = (Ans + G[K]) % MOD;
    }
  }
  cout << Ans << "\n";
}
