#include <bits/stdc++.h>
using namespace std;
long long n, k, A, f = 1, g, M = 1e9 + 7, S = 1, i, j;
string s, t;
int C(int a) {
  for (j = n; j--;)
    if (s[j] != t[(j - a + n) % n]) return 0;
  return 1;
}
int main() {
  cin >> s >> t >> k;
  n = s.size();
  for (; k--; f = (S - f) % M, g = (S - g) % M, S = (f + g * n - g) % M)
    ;
  for (A = (A + f * C(0)) % M, i = n - 1; i--; A = (A + g * C(i + 1)) % M)
    ;
  cout << (A + M) % M;
  return 0;
}
