#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
char S[2000];
char T[2000];
void go(int* A, int* B, int* C, int N) {
  for (int i = 0; i < (N); ++i) C[i] = 0;
  for (int i = 0; i < (N); ++i)
    for (int j = 0; j < (N); ++j)
      C[(i + j) % N] = (C[(i + j) % N] + A[i] * (long long)B[j]) % MOD;
}
int result[2000];
int temp[2000], a[2000], b[2000];
int main() {
  int K;
  scanf("%s%s%d", S, T, &K);
  int N = strlen(S);
  result[0] = 1;
  for (int i = 0; i < (N); ++i)
    if (i > 0) a[i] = 1;
  while (K) {
    if (K & 1) {
      go(result, a, temp, N);
      copy(temp, temp + N, result);
    }
    go(a, a, b, N);
    copy(b, b + N, a);
    K >>= 1;
  }
  long long R = 0;
  for (int i = 0; i < (N); ++i) {
    bool good = true;
    for (int j = 0; j < (N); ++j) {
      good = good && S[j] == T[(i + j) % N];
    }
    if (good) R += result[i];
  }
  printf("%d\n", (int)(R % MOD));
}
