#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 1005;
const long long P = 1000000007;
int N, K, multiplier;
int end_mod;
long long inverse(long long x, long long mod) {
  assert(x != 0LL);
  if (x == 1LL) return 1LL;
  long long y = inverse(mod % x, x);
  long long answer = -((y * mod - 1) / x);
  answer = (answer + mod) % mod;
  return answer;
}
long long fast_pow(long long base, int exp) {
  if (exp == 0) return 1;
  long long x = fast_pow(base, exp / 2) % P;
  return (((x * x) % P) * (exp % 2 == 1 ? base : 1)) % P;
}
bool is_period(string& s, int p) {
  for (int i = 0; i + p < s.length(); i++) {
    if (s[i] != s[i + p]) return false;
  }
  return true;
}
int get_period(string s) {
  int period = s.length();
  for (int i = s.length() - 1; i > 0; i--) {
    if (period % i != 0) continue;
    if (is_period(s, i)) period = i;
  }
  return period;
}
int main() {
  string start, end;
  cin >> start >> end >> K;
  N = start.length();
  int period = get_period(start);
  bool identical = (start == end);
  bool possible = false;
  for (int i = 0; i < N; i++) {
    end = end.substr(1, end.length() - 1) + end.substr(0, 1);
    if (end == start) possible = true;
  }
  if (!possible) {
    cout << "0\n";
    return 0;
  }
  long long x = fast_pow(N - 1, K);
  long long y = fast_pow(-1, K);
  long long z = inverse(N, P);
  long long self = ((x + (N - 1) * y) * z) % P;
  long long other = ((x - y) * z) % P;
  long long answer = (N / period - 1) * other + (identical ? self : other);
  answer %= P;
  cout << answer << '\n';
}
