#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T checkmin(T &a, T b) {
  return (a < b) ? a : a = b;
}
template <class T>
inline T checkmax(T &a, T b) {
  return (a > b) ? a : a = b;
}
template <class T>
T GCD(T a, T b) {
  if (a < 0) return GCD(-a, b);
  if (b < 0) return GCD(a, -b);
  return (a == 0) ? b : GCD(b % a, a);
}
template <class T>
T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;
}
template <class T>
inline T sqr(T X) {
  return X * X;
}
namespace Poor {
const int MaxiN = 1005;
const int MaxiK = 100005;
const int ModNum = 1000000007;
int K, Ans;
int Opt[MaxiK][2];
char A[MaxiN], B[MaxiN];
void Solve() {
  Ans = 0;
  if (strlen(A) != strlen(B)) return;
  int L = strlen(A);
  Opt[0][0] = 1, Opt[0][1] = 0;
  for (int i = 0; i < K; ++i) {
    Opt[i + 1][0] = ((long long)Opt[i][1] * (L - 1)) % ModNum;
    Opt[i + 1][1] = ((long long)Opt[i][1] * (L - 2) + Opt[i][0]) % ModNum;
  }
  for (int i = 0; i < L; ++i) {
    bool Able = 1;
    for (int k = 0; k < L; ++k)
      if (A[(i + k) % L] != B[k]) {
        Able = 0;
        break;
      }
    if (Able) {
      if (i == 0)
        Ans = (Ans + Opt[K][0]) % ModNum;
      else
        Ans = (Ans + Opt[K][1]) % ModNum;
    }
  }
}
void Run() {
  scanf("%s", A);
  scanf("%s", B);
  scanf("%d", &K);
  Solve();
  printf("%d\n", Ans);
}
}  // namespace Poor
int main() {
  Poor::Run();
  return 0;
}
