#include <bits/stdc++.h>
using namespace std;
long long arr[100000 + 5];
long long arr2[100000 + 5];
int main() {
  string a, b;
  int k;
  cin >> a >> b;
  cin >> k;
  int l = a.length();
  int i;
  arr[0] = 1;
  arr2[0] = 0;
  for (i = 1; i <= k; i++) {
    arr[i] = ((l - 1) * arr2[i - 1]) % 1000000007;
    arr2[i] = (((l - 2) * arr2[i - 1]) + arr[i - 1]) % 1000000007;
  }
  string tmp;
  long long ret = 0;
  cerr << arr[k] << ' ' << arr2[k] << endl;
  for (i = 0; i < l; i++) {
    tmp = a.substr(i) + a.substr(0, i);
    cerr << tmp << endl;
    if (tmp == b) {
      if (i)
        ret += arr2[k];
      else
        ret += arr[k];
    }
    ret = ret % 1000000007;
  }
  cout << ret << endl;
}
