#include <bits/stdc++.h>
using namespace std;
const int N = 2010, mod = 1e9 + 7;
int n, k;
char a[N], b[N];
long long f[2][2];
bool check(int start) {
  bool flag = true;
  for (int i = start, j = 0; i <= start + n - 1; i++, j++) {
    if (a[i] != b[j]) {
      flag = false;
      break;
    }
  }
  return flag;
}
int main() {
  int cnt = 0;
  scanf("%s%s%d", a, b, &k);
  n = strlen(a);
  for (int i = 0; i < n; i++) {
    a[n + i] = a[i];
    if (check(i)) cnt++;
  }
  f[0][!check(0)] = 1;
  for (int i = 1; i <= k; i++) {
    f[i & 1][0] = (f[i - 1 & 1][0] * (cnt - 1) + f[i - 1 & 1][1] * cnt) % mod;
    f[i & 1][1] =
        (f[i - 1 & 1][0] * (n - cnt) + f[i - 1 & 1][1] * (n - 1 - cnt)) % mod;
  }
  cout << f[k & 1][0] << endl;
  return 0;
}
