#include <bits/stdc++.h>
char stra[1001], strb[1001];
int k, len;
int solve() {
  long long a = 1;
  long long b = 0;
  long long lb = 0;
  long long l = len - 1;
  for (int i = 0; i < k; ++i) {
    long long tmpa = a;
    long long tmpb = b;
    a = b;
    b = tmpa + lb * (l - 1);
    b %= 1000000007;
    lb = b;
    b *= l;
    b %= 1000000007;
  }
  long long res = 0;
  for (int i = 0; i < len; ++i) {
    bool g = 1;
    for (int j = 0; j < len && g; ++j)
      if (stra[(i + j) % len] != strb[j]) g = 0;
    if (g) {
      if (i == 0)
        res += a;
      else
        res += lb;
      res %= 1000000007;
    }
  }
  return res;
}
int main() {
  scanf("%s%s", stra, strb);
  scanf("%d", &k);
  len = strlen(stra);
  printf("%d\n", solve());
  return 0;
}
