#include <bits/stdc++.h>
const int intINF = 999999999;
const long long i64INF = 99999999999999999ll;
const double doubleINF = 9999999999.;
using namespace std;
int al, bl;
char A[1111], B[1111];
long long res = 0, md = 1000000007;
long long F[3][100011];
bool eq(int p) {
  bool eqq = true;
  for (int i = 0; i < al; i++)
    if (A[(p + i) % al] != B[i]) eqq = false;
  return eqq;
}
int main() {
  char c;
  while (scanf("%c", &c), c != '\n') A[al++] = c;
  while (scanf("%c", &c), c != '\n') B[bl++] = c;
  int k, cc;
  scanf("%d", &k);
  F[0][0] = 1;
  F[1][0] = 0;
  F[2][0] = 1;
  for (int i = 1; i <= k; i++) {
    F[0][i] = F[2][i - 1] - F[0][i - 1];
    if (F[0][i] < 0) F[0][i] += md;
    F[1][i] = F[2][i - 1] - F[1][i - 1];
    if (F[1][i] < 0) F[1][i] += md;
    F[2][i] = (F[0][i] + (al - 1) * F[1][i]) % md;
  }
  for (int i = 0; i < al; i++)
    if (eq(i)) {
      if (i == 0)
        cc = 0;
      else
        cc = 1;
      res += F[cc][k];
      res %= md;
    }
  printf("%I64d\n", res);
  return 0;
}
