#include <bits/stdc++.h>
using namespace std;
int cnt[1000];
int main() {
  string start, end;
  cin >> start >> end;
  int k, n = start.length();
  cin >> k;
  memset(cnt, 0, sizeof(cnt));
  cnt[0] = 1;
  for (int i = 0; i < k; ++i) {
    int s = 0;
    for (int i = 0; i < n; ++i) s = (s + cnt[i]) % 1000000007;
    s += 1000000007;
    for (int i = 0; i < n; ++i) {
      cnt[i] = (s - cnt[i]) % 1000000007;
    }
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    if (start == end.substr(i) + end.substr(0, i)) {
      res = (res + cnt[i]) % 1000000007;
    }
  }
  cout << res << endl;
  return 0;
}
