#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
map<string, int> m;
void shift(string &s) {
  char c = s[s.length() - 1];
  for (int i = s.length() - 2; i + 1; i--) swap(s[i], s[i + 1]);
}
int main() {
  ios::sync_with_stdio(false);
  string s, t, ss, tt;
  cin >> s >> t;
  ss = s, tt = t;
  int n = s.length(), k, can = 0;
  cin >> k;
  if (k == 0) {
    if (s != t)
      cout << 0 << endl;
    else
      cout << 1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    shift(s);
    m[s]++;
    if (s == t) can = true;
  }
  if (!can) {
    cout << 0 << endl;
    return 0;
  }
  long long x, y, A = m[tt], B = n - A;
  if (tt == ss)
    x = 1, y = 0;
  else
    x = 0, y = 1;
  for (int i = 1; i <= k; i++) {
    long long tx, ty;
    tx = x * (A - 1) + y * A;
    ty = x * B + y * (B - 1);
    x = tx % M;
    y = ty % M;
  }
  cout << x << endl;
  return 0;
}
