#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  int n, k, p = 0;
  string s, t, q;
  cin >> s >> t >> k;
  n = s.length();
  q = s + s;
  for (int i = 0; i < n; i++)
    if (q.substr(i, n) == t) p++;
  long long f = (s == t), g = 1 - f;
  for (int i = 0; i < k; i++) {
    long long f2 = f * (p - 1) + g * p;
    long long g2 = f * (n - p) + g * (n - p - 1);
    f = f2 % mod;
    g = g2 % mod;
  }
  printf("%d\n", f);
  return 0;
}
