#include <bits/stdc++.h>
using namespace std;
int A, B;
bool pos = false;
string s1, s2, temp_string_1, temp_string_2;
int comb_type;
int total_comb_number;
int length;
char last_char, temp_c;
long long ans;
int i, j, k;
vector<int> mil;
int main() {
  cin >> s1 >> s2 >> k;
  if (k == 0) {
    if (s1 == s2)
      cout << 1 << endl;
    else
      cout << 0;
    return 0;
  }
  length = s1.size();
  total_comb_number = length;
  string comb[total_comb_number];
  comb[0] = s1;
  for (i = 1; i < length; i++) {
    temp_string_1 = comb[i - 1];
    last_char = temp_string_1[length - 1];
    temp_string_1.erase(length - 1);
    temp_string_1.insert(0, 1, last_char);
    comb[i] = temp_string_1;
  }
  for (i = 0; i < total_comb_number; i++) {
    if (s2 == comb[i]) {
      pos = true;
      mil.push_back(i);
    }
  }
  if (!pos) {
    cout << 0 << endl;
    return 0;
  }
  if (k == 1) {
    cout << mil.size() - 1 << endl;
    return 0;
  }
  for (i = 0; i < total_comb_number; i++) {
    if (comb[i] == s1)
      A++;
    else
      B++;
  }
  long long dpA[k + 1], dpB[k + 1];
  if (s2 == s1) {
    dpA[0] = 1;
    dpB[0] = 0;
  } else {
    dpA[0] = 0;
    dpB[0] = 1;
  }
  for (int n = 1; n <= k; n++) {
    dpA[n] = (dpA[n - 1] * (A - 1) + dpB[n - 1] * A) % 1000000007;
    dpB[n] = (dpA[n - 1] * B + dpB[n - 1] * (B - 1)) % 1000000007;
  }
  cout << dpA[k] << endl;
  return 0;
}
