#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int N = 100009;
const int mod = inf + 7;
int type[N];
long long f[N][2];
int cnt[2];
int main() {
  std::ios::sync_with_stdio(false);
  string s, t;
  int m;
  cin >> s >> t >> m;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (s == t) {
      type[i] = 1;
      cnt[1]++;
    } else {
      type[i] = 0;
      cnt[0]++;
    }
    s = s.substr(1, n - 1) + s[0];
  }
  f[0][type[0]] = 1;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      if (!f[i][j]) continue;
      for (int k = 0; k < 2; k++)
        f[i + 1][k] = (f[i + 1][k] + f[i][j] * (cnt[k] - (j == k))) % mod;
    }
  }
  cout << f[m][1] << endl;
}
