#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  string a, b;
  int k;
  cin >> a >> b >> k;
  int n = a.length(), l = 0;
  long long gd = 0, bd = 0;
  int f = 0;
  if (a.length() != b.length()) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    int j;
    for (j = 0; j < n; j++)
      if (a[(i + j) % n] != a[j]) break;
    if (j == n)
      gd++;
    else
      bd++;
    for (j = 0; j < n; j++)
      if (a[(i + j) % n] != b[j]) break;
    if (j == n) f = 1;
  }
  if (f == 0) {
    cout << 0;
    return 0;
  }
  vector<int> dp(2, 0), dp1(2, 0);
  if (a == b)
    dp[0] = 1;
  else
    dp1[0] = 1;
  long long mod = 1e9 + 7;
  for (int i = 1; i <= k; i++) {
    long long x = dp[1 - i % 2] * (gd - 1) + dp1[1 - i % 2] * gd;
    x %= mod;
    dp[i % 2] = x;
    x = dp[1 - i % 2] * bd + dp1[1 - i % 2] * (bd - 1);
    x %= mod;
    dp1[i % 2] = x;
  }
  cout << dp[k % 2] << "\n";
  return 0;
}
