#include <bits/stdc++.h>
char str1[1010], str2[1010];
int n;
int len1, len2;
int cycle;
int shift;
int main(int argc, const char* argv[]) {
  scanf("%s%s%d", &str1, &str2, &n);
  for (len1 = 0; str1[len1]; len1++)
    ;
  for (len2 = 0; str2[len2]; len2++)
    ;
  cycle = len1;
  for (int i = 1; i * i <= len1; i++) {
    if ((len1 % i) == 0) {
      bool isCycle = true;
      for (int j = i; j < len1; j++) {
        if (str1[j] != str1[j % i]) isCycle = false;
      }
      if (isCycle) {
        cycle = i;
        break;
      }
    }
  }
  if (cycle == len1) {
    int beg = (int)(sqrt((double)len1) + 0.000001);
    for (int i = beg; i > 0; i--) {
      if ((len1 % i) == 0) {
        bool isCycle = true;
        int start = len1 / i;
        for (int j = start; j < len1; j++) {
          if (str1[j] != str1[j % start]) isCycle = false;
        }
        if (isCycle) {
          cycle = start;
          break;
        }
      }
    }
  }
  for (shift = 0; shift < len1; shift++) {
    int i;
    for (i = 0; i < len1; i++) {
      if (str1[i] != str2[(i + shift) % len1]) break;
    }
    if (i == len1) break;
  }
  if (shift == len1) {
    printf("0\n");
    return 0;
  }
  shift %= cycle;
  long long results[100010][2];
  long long mod = 1000000007;
  int cycle2 = len1 / cycle;
  for (int i = 0; i <= 100000; i++) {
    results[i][0] = 0;
    results[i][1] = 0;
  }
  if (shift == 0)
    results[0][0] = 1;
  else {
    results[0][1] = 1;
  }
  for (int i = 0; i < n; i++) {
    results[i + 1][0] =
        (cycle2 * results[i][1] + (cycle2 - 1) * results[i][0]) % mod;
    results[i + 1][1] = ((len1 - cycle2) * results[i][0] +
                         (len1 - cycle2 - 1) * results[i][1]) %
                        mod;
  }
  std::cout << results[n][0];
  return 0;
}
