#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7, Max = 1000 + 3;
string s1, s2;
int k, n, ans, mat[Max][Max];
vector<int> vec;
void pow() {
  for (int i = 31; i >= 0; i--) {
    long long a1 = 0, b1 = 0;
    for (int j = 0; j < n; j++) {
      a1 += ((long long)mat[j][0] * (long long)mat[0][j]) % mod;
      a1 %= mod;
    }
    for (int j = 0; j < n; j++) {
      b1 += ((long long)mat[j][0] * (long long)mat[1][j]) % mod;
      b1 %= mod;
    }
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) mat[i][j] = mat[j][i] = b1;
    for (int i = 0; i < n; i++) mat[i][i] = a1;
    if ((k >> i) & 1) {
      a1 = b1 = 0;
      for (int j = 1; j < n; j++) {
        a1 += (long long)mat[j][0] % mod;
        a1 %= mod;
      }
      b1 = mat[0][0];
      for (int i = 2; i < n; i++) {
        b1 += (long long)mat[i][0] % mod;
        b1 %= mod;
      }
      for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++) mat[i][j] = mat[j][i] = b1;
      for (int i = 0; i < n; i++) mat[i][i] = a1;
    }
  }
  return;
}
int main() {
  cin >> s1 >> s2 >> k;
  n = (int)s1.size();
  int p;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    int pt = 0, cnt = 0, ip = i;
    while (cnt < n) {
      if (s1[pt] != s2[ip]) break;
      pt = (pt + 1) % n, ip = (ip + 1) % n;
      cnt++;
    }
    if (cnt == n) flag = true, vec.push_back(i);
  }
  if (!flag)
    cout << 0 << endl;
  else {
    for (int i = 0; i < n; i++) mat[i][i] = 1;
    pow();
    for (int i = 0; i < (int)vec.size(); i++) ans += mat[0][vec[i]], ans %= mod;
    cout << ans << endl;
  }
  return 0;
}
