#include <bits/stdc++.h>
using namespace std;
using namespace std;
inline int in() {
  int x = 0, c;
  for (; (unsigned int)((c = getchar()) - '0') >= 10;) {
    if (c == '-') return -in();
    if (!~c) throw ~0;
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while ((unsigned int)((c = getchar()) - '0') < 10);
  return x;
}
inline int gcd(int a, int b) {
  if (a > b) swap(a, b);
  return a == 0 ? b : gcd(b % a, a);
}
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
const int mod = 1e9 + 7;
string st, ed, re;
int K, len, x, y;
long long g[100005], b[100005];
int main() {
  getline(cin, st);
  getline(cin, ed);
  K = in();
  len = st.size();
  re = st + st;
  for (int i = 0; i < len; i++)
    if (re.substr(i, len) == ed) x++;
  y = len - x;
  g[0] = (st == ed);
  b[0] = (st != ed);
  for (int i = 1; i <= K + 1; i++) {
    g[i] = (g[i - 1] * (x - 1) % mod + b[i - 1] * x % mod) % mod;
    b[i] = (g[i - 1] * y % mod + b[i - 1] * (y - 1) % mod) % mod;
  }
  cout << g[K];
  return 0;
}
