#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 7;
const long long MOD = (1e9) + 7;
const unsigned long long maxc = 26 + 1;
struct Matrix {
  long long v[2][2];
  void init() { memset(v, 0, sizeof(v)); }
  Matrix operator*(const Matrix &b) {
    Matrix temp;
    temp.init();
    for (int i = 0; i <= 1; i++)
      for (int j = 0; j <= 1; j++)
        for (int k = 0; k <= 1; k++)
          temp.v[i][j] = (temp.v[i][j] + v[i][k] * b.v[k][j]) % MOD;
    return temp;
  }
} Mba, M;
int K, n, god, bad;
unsigned long long cur, sth, org, p[maxn];
char s[maxn], t[maxn];
Matrix qpow(Matrix Mba, int k) {
  Matrix temp;
  if (k == 0) {
    temp.v[0][0] = temp.v[1][1] = 1, temp.v[0][1] = temp.v[1][0] = 0;
    return temp;
  } else {
    temp = qpow(Mba, k >> 1);
    if (k & 1)
      return temp * temp * Mba;
    else
      return temp * temp;
  }
}
int main() {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  scanf("%d", &K);
  p[0] = 1, n = strlen(s + 1);
  for (int i = 1; i <= n; i++)
    sth = sth * maxc + (unsigned long long)(t[i] - 'a' + 1),
    p[i] = p[i - 1] * maxc;
  for (int i = 1; i <= n; i++)
    cur = cur * maxc + (unsigned long long)(s[i] - 'a' + 1);
  org = cur;
  if (cur == sth)
    ++god;
  else
    ++bad;
  for (int i = 2; i <= n; i++) {
    cur -= p[n - 1] * (unsigned long long)(s[i - 1] - 'a' + 1);
    cur = (cur * maxc) + (unsigned long long)(s[i - 1] - 'a' + 1);
    if (cur == sth)
      ++god;
    else
      ++bad;
  }
  Mba.init();
  Mba.v[0][0] = god - 1, Mba.v[0][1] = god, Mba.v[1][0] = bad,
  Mba.v[1][1] = bad - 1;
  M = qpow(Mba, K);
  if (org == sth)
    printf("%I64d\n", M.v[0][0]);
  else
    printf("%I64d\n", M.v[0][1]);
  return 0;
}
