#include <bits/stdc++.h>
const int MAXN = 2e5 + 15;
using namespace std;
long long dpA[MAXN], dpB[MAXN];
void solve() {
  string a, b;
  cin >> a >> b;
  int n = a.length();
  int k;
  cin >> k;
  int A = 0, B;
  for (int i = 0; i < n; i++) {
    int first = 1;
    for (int j = 0; j < n; j++) {
      if (a[j] != b[(i + j) % n]) {
        first = 0;
        break;
      }
    }
    if (first) A++;
  }
  B = n - A;
  if (a == b)
    dpA[0] = 1;
  else
    dpB[0] = 1;
  for (int i = 1; i <= k; i++) {
    dpA[i] =
        ((dpA[i - 1] * (A - 1)) % 1000000007 + (dpB[i - 1] * A) % 1000000007) %
        1000000007;
    dpB[i] =
        ((dpA[i - 1] * B) % 1000000007 + (dpB[i - 1] * (B - 1)) % 1000000007) %
        1000000007;
  }
  cout << dpA[k];
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cout << fixed << setprecision(12);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\n";
  }
  return 0;
}
