#include <bits/stdc++.h>
using namespace std;
const int N = 10000000 + 5, mod = 1000000007;
const long long hash_num = 20000623LL;
char s1[N], s2[N];
int a[N], b[N];
int n;
long long k, cnt1, cnt2, hash_a, hash_b, fac_n;
bool org_ok;
inline long long get_hash(int *a, int n) {
  long long ret = 0;
  for (int i = 1; i <= n; i++) ret = ret * hash_num + a[i];
  return ret;
}
struct Matrix {
  long long a[3][3];
  void init_zero() { memset(a, 0LL, sizeof(a)); }
  void init_unit() {
    memset(a, 0LL, sizeof(a));
    for (int i = 1; i <= 2; i++) a[i][i] = 1LL;
  }
  void init_all(long long a1, long long a2, long long a3, long long a4) {
    a[1][1] = a1;
    a[1][2] = a2;
    a[2][1] = a3;
    a[2][2] = a4;
  }
  Matrix operator*(const Matrix &x) {
    Matrix ret;
    ret.init_zero();
    for (int i = 1; i <= 2; i++)
      for (int j = 1; j <= 2; j++) {
        for (int k = 1; k <= 2; k++)
          ret.a[i][j] = ret.a[i][j] + a[i][k] * x.a[k][j];
        ret.a[i][j] %= mod;
      }
    return ret;
  }
  Matrix operator*=(const Matrix &x) {
    *this = *this * x;
    return *this;
  }
  Matrix operator^(long long x) {
    Matrix ret, tmp;
    ret.init_unit();
    tmp.init_unit();
    tmp *= *this;
    while (x) {
      if (x & 1LL) ret *= tmp;
      tmp *= tmp;
      x >>= 1LL;
    }
    return ret;
  }
  Matrix operator^=(long long x) {
    *this = *this ^ x;
    return *this;
  }
} mul;
inline void init_fac() {
  fac_n = 1;
  for (int i = 2; i <= n; i++) fac_n = fac_n * hash_num;
}
int main() {
  scanf("%s%s%lld", s1, s2, &k);
  n = strlen(s1);
  for (int i = 0; i <= n - 1; i++) {
    a[i + 1] = (int)s1[i] - 'a' + 1;
    b[i + 1] = (int)s2[i] - 'a' + 1;
  }
  init_fac();
  hash_a = get_hash(a, n);
  hash_b = get_hash(b, n);
  org_ok = hash_a == hash_b;
  cnt1 = org_ok;
  for (int i = 1; i <= n - 1; i++) {
    hash_a = (hash_a - a[i] * fac_n) * hash_num + a[i];
    if (hash_a == hash_b) cnt1++;
  }
  cnt2 = n - cnt1;
  mul.init_all(cnt1 - 1, cnt1, cnt2, cnt2 - 1);
  mul ^= k;
  printf("%lld\n", org_ok ? mul.a[1][1] : mul.a[1][2]);
  return 0;
}
