#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T t) {
  return t < 0 ? -t : t;
}
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
const int N = 1005;
int n, k, val;
char a[N], b[N];
long long A, B;
long long memog[100005], memob[100005];
long long solve_bad(int x);
long long solve_good(int x) {
  if (x == 0) return val;
  long long &m = memog[x];
  if (m != -1) return m;
  m = mod(mod(solve_good(x - 1) * (A - 1)) + mod(solve_bad(x - 1) * A));
  return m;
}
long long solve_bad(int x) {
  if (x == 0) return !val;
  long long &m = memob[x];
  if (m != -1) return m;
  m = mod(mod(solve_bad(x - 1) * (B - 1)) + mod(solve_good(x - 1) * B));
  return m;
}
int main() {
  int i, j;
  scanf("%s %s", a, b);
  n = strlen(a);
  scanf("%d", &k);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++)
      if (a[(j + i + 1) % n] != b[j]) {
        B++;
        break;
      }
    if (j == n) A++;
  }
  val = !strcmp(a, b);
  memset(memog, -1, sizeof memog);
  memset(memob, -1, sizeof memob);
  cout << solve_good(k) << '\n';
  return 0;
}
