#include <bits/stdc++.h>
using namespace std;
string a, b;
long long la, lb;
bool IS(int i) {
  for (int j = 0; j < la; j++) {
    if (a[(i + j) % la] != b[j]) return 0;
  }
  return 1;
}
int k;
int main() {
  cin >> a >> b >> k;
  if (k == 0) {
    if (a == b)
      cout << "1" << endl;
    else
      cout << "0" << endl;
    return 0;
  }
  la = a.length();
  lb = b.length();
  long long val1 = 0;
  long long val2 = 1;
  for (int i = 1; i < k; i++) {
    long long tmp = ((val2 * (long long)(la - 1LL))) % 1000000007;
    val2 = (val1 + val2 * (long long)(la - 2LL)) % 1000000007;
    val1 = tmp;
  }
  long long sol = 0;
  for (int i = 0; i < la; i++) {
    if (IS(i)) {
      if (!i)
        sol = (sol + val1) % 1000000007;
      else
        sol = (sol + val2) % 1000000007;
    }
  }
  cout << sol << endl;
  return 0;
}
