#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const long long mdl = 1000 * 1000 * 1000 + 7;
int main() {
  string st1, st2;
  int k;
  cin >> st1 >> st2 >> k;
  int n = st1.length();
  long long one = 1, other = 0, none, nother;
  for (int i = 0; i < k; i++) {
    none = other * (n - 1) % mdl;
    nother = (one + other * (n - 2)) % mdl;
    one = none;
    other = nother;
  }
  long long ans = 0;
  if (st1 == st2) ans = ans + one;
  for (int i = 0; i < n - 1; i++) {
    st2 = st2 + st2[0];
    st2.erase(st2.begin());
    if (st1 == st2) ans = ans + other;
  }
  cout << ans % mdl << endl;
  return 0;
}
