#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int md = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  int k;
  cin >> s >> t >> k;
  int n = (int)(s.size());
  int good = 0, bad = 0;
  for (int i = 0; i < n; i++) {
    string cur = s.substr(i + 1, n - 1 - i);
    cur += s.substr(0, i + 1);
    good += (cur == t);
  }
  bad = n - good;
  long long dpg[k + 1], dpb[k + 1];
  if (s == t) {
    dpg[0] = 1;
    dpb[0] = 0;
  } else {
    dpg[0] = 0;
    dpb[0] = 1;
  }
  for (int i = 1; i <= k; i++)
    dpg[i] = ((good - 1) * dpg[i - 1] + good * dpb[i - 1]) % md,
    dpb[i] = ((bad - 1) * dpb[i - 1] + bad * dpg[i - 1]) % md;
  cout << dpg[k];
}
