#include <bits/stdc++.h>
using namespace std;
const int DX[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int DY[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const int intmax = 0x7fffffff;
const int mod = 1000000007;
template <class DT>
DT gcd(DT a, DT b) {
  if (b) return gcd(b, a % b);
  return a;
}
template <class DT>
void exgcd(DT a, DT b, DT &d, DT &x, DT &y) {
  if (b)
    exgcd(b, a % b, d, y, x), y -= x * (a / b);
  else
    d = a, x = 1, y = 0;
}
template <class DT>
inline DT inv(DT a, DT m) {
  DT x, y, d;
  exgcd(a, m, d, x, y);
  if (d == 1) return (x + m) % m;
  return -1;
}
template <class DT1, class DT2>
inline DT2 Mod(DT1 a, DT2 mod) {
  if (a < 0) return (a % mod + mod) % mod;
  return a % mod;
}
template <class DT, class DT1, class DT2>
inline DT mulm(DT1 a, DT2 b, DT mod) {
  DT ta(Mod(a, mod)), tb(Mod(b, mod));
  if (ta <= intmax && tb <= intmax) return 1ll * ta * tb % mod;
  DT ret(0);
  if (ta < tb) swap(ta, tb);
  for (; tb; tb >>= 1) {
    if (tb & 1) ret = (ret + ta) % mod;
    ta = (ta + ta) % mod;
  }
  return ret;
}
template <class DT>
inline DT mulm(int a, int b, DT mod) {
  return Mod(1ll * a * b, mod);
}
template <class DT, class DT1, class DT2>
inline DT expm(DT1 a, DT2 b, DT mod) {
  assert(b >= 0);
  DT ret(1), ta(Mod(a, mod));
  for (; b; b >>= 1) {
    if (b & 1) ret = mulm(ret, ta, mod);
    ta = mulm(ta, ta, mod);
  }
  return ret;
}
char s1[1005], s2[1005], ns[1005];
int n;
map<string, int> mp;
map<string, int>::iterator mit;
int main() {
  scanf("%s%s%d", s1, s2, &n);
  int l = strlen(s1);
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    if (i & 1)
      ans = (1ll * ans * (l - 1) - (l - 2) + mod) % mod;
    else
      ans = (1ll * ans * (l - 1)) % mod;
  }
  if (strcmp(s1, s2) == 0) {
    int find = 0;
    for (int i = 1; i < l; i++) {
      for (int j = i; j < i + l; j++) ns[j - i] = s1[j % l];
      if (strcmp(ns, s2) == 0) find++;
    }
    if (n & 1)
      printf("%d\n", (1ll * find * ans + ans - 1) % mod);
    else
      printf("%d\n", (1ll * find * (ans - 1) + ans) % mod);
  } else {
    int find = 0;
    for (int i = 1; i < l; i++) {
      for (int j = i; j < i + l; j++) ns[j - i] = s1[j % l];
      if (strcmp(ns, s2) == 0) find++;
    }
    if (find) {
      if (n & 1)
        printf("%d\n", (1ll * ans * find) % mod);
      else
        printf("%d\n", 1ll * find * (ans - 1) % mod);
    } else
      puts("0");
  }
}
