#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  string a, b;
  int k;
  cin >> a >> b;
  cin >> k;
  int n = a.size();
  if (k == 0 && a == b) {
    cout << 1 << endl;
    return 0;
  }
  if (k == 0) {
    cout << 0 << endl;
    return 0;
  }
  long long val0 = 0, val1 = 1, val0t = 0;
  for (int i = 0; i < k - 1; ++i) {
    val0t = (val1 * (n - 1)) % 1000000007ll;
    val1 = (val1 * (n - 2) + val0) % 1000000007ll;
    val0 = val0t;
  }
  long long ans = 0;
  if (a == b) ans += val0;
  for (int i = 1; i < n; ++i) {
    int flag = 1;
    for (int j = 0; j < n; ++j)
      if (a[j] != b[(i + j) % n]) {
        flag = 0;
        break;
      }
    if (flag) ans = (ans + val1) % 1000000007ll;
  }
  cout << (ans) % 1000000007ll << endl;
  return 0;
}
