#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
long long fg[100007], fb[100007], k, g_g, g_b, b_g, b_b, l;
void dp(int n) {
  if (n > k) {
    return;
  }
  fg[n] = (fg[n - 1] * g_g + fb[n - 1] * b_g) % MOD;
  fb[n] = (fg[n - 1] * g_b + fb[n - 1] * b_b) % MOD;
  dp(n + 1);
}
int main() {
  string start, end;
  cin >> start;
  cin >> end;
  cin >> k;
  l = start.size();
  int m = 0;
  for (int i = 0; i < l; i++) {
    string t = start.substr(l - i, i) + start.substr(0, l - i);
    if (t == end) {
      m++;
    }
  }
  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }
  g_g = m - 1;
  g_b = l - m;
  b_g = m;
  b_b = l - m - 1;
  if (start == end) {
    fg[0] = 1;
    fb[0] = 0;
  } else {
    fg[0] = 0;
    fb[0] = 1;
  }
  dp(1);
  cout << fg[k] << endl;
  return 0;
}
