#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
string s1, s2;
int k, n;
long long ans = 0, l1 = 0, l2 = 1;
int main() {
  ios_base::sync_with_stdio(0);
  getline(cin, s1);
  getline(cin, s2);
  cin >> n;
  k = s1.length() - 1;
  if (n == 0) {
    if (s1 == s2)
      cout << 1 << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  int sovp = 0;
  string s = s2 + s2;
  for (int i = 1; i <= k; ++i) {
    bool f = true;
    for (int j = 0; j <= k; ++j) {
      if (s[i + j] != s1[j]) {
        f = false;
        break;
      }
    }
    if (f) ++sovp;
  }
  for (int i = 1; i < n; ++i) {
    long long tl1 = l2 * k;
    long long tl2 = l2 * (k - 1) + l1;
    l1 = tl1 % MOD;
    l2 = tl2 % MOD;
  }
  int ans = 0;
  if (s1 == s2)
    ans = (l1 + l2 * sovp) % MOD;
  else
    ans = (l2 * sovp) % MOD;
  cout << ans << endl;
  return 0;
}
