#include <bits/stdc++.h>
using namespace std;
inline int ni() {
  int a;
  scanf("%d", &a);
  return a;
}
const int max_n = 1000, max_k = 1000000;
const long long mod = 1000000007;
int d[2][max_n];
char from[max_n + 1], to[max_n + 1];
bool same(int n, int ind) {
  int i = 0, k = ind, j = 0;
  while (k < n) {
    if (from[k] != to[i]) {
      return false;
    }
    ++k;
    ++i;
  }
  while (j < ind) {
    if (from[j] != to[i]) {
      return false;
    }
    ++j;
    ++i;
  }
  return true;
}
int main() {
  scanf("%s", from);
  scanf("%s", to);
  long long n = strlen(from), k = ni();
  long long first = 1, anothers = 0;
  for (int i = 0; i < int(k); i++) {
    int cur = (i & 1), next = 1 - cur;
    long long new_anothers = (first + (n - 2) * anothers) % mod;
    long long new_first = ((n - 1) * anothers) % mod;
    anothers = new_anothers;
    first = new_first;
  }
  long long res = 0;
  for (int i = 0; i < int(n); i++) {
    if (same(n, i)) {
      if (i == 0) {
        res += first;
        res %= mod;
      } else {
        res += anothers;
        res %= mod;
      }
    }
  }
  while (res < 0) res += mod;
  cout << res << endl;
  return 0;
}
