#include <bits/stdc++.h>
using namespace std;
int reach(string st, string en) {
  int cnt = 0;
  for (int i = 1; i < st.size(); ++i) {
    if (st.substr(i) + st.substr(0, i) == en) ++cnt;
  }
  return cnt;
}
long long int dp[1001];
int main() {
  int k;
  string st, en;
  cin >> st >> en >> k;
  if (k == 0)
    cout << (st == en) << endl;
  else {
    int w = reach(st, en);
    if (w != 0 || st == en) {
      long long int ans = 0;
      if (k == 1)
        ans = w;
      else {
        k--;
        long long int num = st.size() - 1;
        long long int me = 0, ot = 1;
        for (int i = 0; i < k; ++i) {
          long long int tm = me;
          me = (num * ot) % 1000000007;
          ot = ((num - 1) * ot + tm) % 1000000007;
        }
        int w = reach(st, en);
        if (st == en) {
          ans = me + w * ot;
        } else {
          ans = w * ot;
        }
      }
      cout << ans % 1000000007 << endl;
    } else
      cout << 0 << endl;
  }
  return 0;
}
