#include <bits/stdc++.h>
using namespace std;
char A[1001], B[1001];
int n, m;
bool pos(int j) {
  if (n != m) return 0;
  for (int i = 0, cur = j; i < m; ++i, cur++, cur %= m)
    if (A[cur] != B[i]) return 0;
  return 1;
}
int main() {
  cin >> A >> B;
  n = strlen(A);
  m = strlen(B);
  long long frst = 0, tot = 0;
  frst = pos(0);
  for (int i = 1; i < n; ++i) tot += pos(i);
  int k;
  cin >> k;
  long long n0 = 1;
  long long no = 0;
  long long omar = n - 1;
  long long bakr = n - 2;
  for (int i = 1; i <= k; ++i) {
    long long lst0 = n0, lst = no;
    n0 = omar * no % 1000000007;
    no = (lst0 + bakr * lst) % 1000000007;
  }
  long long ans = (frst * n0 % 1000000007 + tot * no % 1000000007) % 1000000007;
  cout << ans << endl;
}
