#include <bits/stdc++.h>
using namespace std;
const int N = 2048;
const int K = 1 << 17;
const int MOD = (1e9) + 7;
int n, k;
char a[N], b[N];
bool used[2][K];
int state[2][K];
int good, bad;
bool is_good[N];
int cnt;
int recurse(int which, int rem) {
  if (rem == 0) return which;
  if (used[which][rem]) return state[which][rem];
  long long ans = 0;
  if (which == 0)
    ans += recurse(0, rem - 1) * 1ll * (bad - 1);
  else
    ans += recurse(0, rem - 1) * 1ll * bad;
  if (which == 1)
    ans += recurse(1, rem - 1) * 1ll * (good - 1);
  else
    ans += recurse(1, rem - 1) * 1ll * good;
  ans %= MOD;
  used[which][rem] = true;
  state[which][rem] = ans;
  return ans;
}
int main() {
  int tests, current_case;
  int i, j;
  tests = 1;
  for (current_case = 1; current_case <= tests; current_case++) {
    scanf("%s", a + 1);
    scanf("%s", b + 1);
    n = strlen(a + 1);
    scanf("%d", &k);
    good = 0;
    bad = 0;
    for (i = 1; i <= n; i++) a[i + n] = a[i];
    for (i = 1; i <= n; i++) {
      cnt = 0;
      for (j = 1; j <= n; j++)
        if (a[i + j - 1] == b[j]) ++cnt;
      if (cnt == n)
        ++good, is_good[i] = true;
      else
        ++bad, is_good[i] = false;
    }
    memset(used, 0, sizeof(used));
    printf("%d\n", recurse(is_good[1], k));
  }
  return 0;
}
