#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long goods = 0;
long long bads = 0;
int steps, len;
long long good[100010];
long long bad[100010];
string a, b, c;
bool self = false;
int main() {
  cin >> a >> b;
  cin >> steps;
  len = a.length();
  if (a == b) goods++, self = true;
  c = a.substr(1, len - 1) + a[0];
  for (int i = 1; i < len; i++) {
    if (c == b) goods++;
    c = c.substr(1, len - 1) + c[0];
  }
  bads = len - goods;
  good[1] = goods - (self);
  bad[1] = len - 1 - good[1];
  if (self) good[0] = 1;
  for (int i = 2; i <= steps; i++) {
    good[i] =
        ((good[i - 1] * (goods - 1)) % MOD + (bad[i - 1] * goods) % MOD) % MOD;
    if (i == steps) break;
    bad[i] =
        ((good[i - 1] * bads) % MOD + (bad[i - 1] * (bads - 1)) % MOD) % MOD;
  }
  printf("%I64d\n", good[steps]);
  return 0;
}
