#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const double infd = 2e+9;
const int infi = 1ll << 30;
const long long infl = 1ll << 60;
const int mod = 1e+9 + 7;
template <class T>
inline T sqr(T x) {
  return x * x;
}
int main() {
  string a, b;
  int k;
  cin >> a >> b >> k;
  int n = a.length();
  vector<int> p(k + 1);
  p[0] = 1;
  for (int i = 1; i <= k - 1; i++) p[i] = p[i - 1] * 1ll * (n - 1) % mod;
  vector<int> d[2];
  d[0].resize(k + 1);
  d[1].resize(k + 1);
  d[0][0] = 1;
  d[1][0] = 0;
  for (int i = 1; i <= k; i++) {
    for (int m = 0; m < 2; m++) d[m][i] = (p[i - 1] - d[m][i - 1] + mod) % mod;
  }
  int result = 0;
  for (int i = 0; i < n; i++) {
    bool compactible = true;
    for (int j = 0; j < n; j++) {
      if (b[(i + j) % n] != a[j]) {
        compactible = false;
        break;
      }
    }
    if (compactible) {
      if (i == 0)
        result += d[0][k];
      else
        result += d[1][k];
      result %= mod;
    }
  }
  cout << result;
  return 0;
}
