#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long G, F, f, g;
int n, ans, k;
char s[1100], t[1100];
int main() {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  n = strlen(s + 1);
  f = 1, g = 0;
  scanf("%d", &k);
  while (k--) {
    G = (g * (n - 2) + f) % mod;
    F = g * (n - 1) % mod;
    f = F, g = G;
  }
  bool can = 1;
  for (int i = 1; i <= n && can; ++i)
    if (s[i] != t[i]) can = 0;
  if (can) ans = f;
  for (int i = 2; i <= n; ++i) {
    can = 1;
    for (int j = i, k = 1; k <= n && can; ++k, j = j % n + 1)
      if (t[k] != s[j]) can = 0;
    if (can) ans = (ans + g) % mod;
  }
  printf("%d\n", ans);
}
