#include <bits/stdc++.h>
using namespace std;
int l, k, cnt;
long long dp[100005][2];
char r[2005], s[1005];
bool no;
int main() {
  scanf("%s%s%d", r, s, &k);
  l = strlen(r);
  for (int i = 0; i < l; i++) {
    r[l + i] = r[i];
  }
  cnt = 0;
  for (int i = 0; i < l; i++) {
    bool flag = true;
    for (int j = 0; j < l; j++) {
      if (r[i + j] != s[j]) {
        flag = false;
        break;
      }
    }
    if (i == 0) no = flag;
    if (flag) cnt++;
  }
  dp[0][0] = dp[0][1] = 0;
  if (no) {
    dp[0][1] = 1;
  } else {
    dp[0][0] = 1;
  }
  for (int i = 1; i <= k; i++) {
    dp[i][0] = dp[i][1] = 0;
    dp[i][0] += dp[i - 1][0] * max(0, l - cnt - 1);
    dp[i][0] %= 1000000007;
    dp[i][0] += dp[i - 1][1] * max(0, l - cnt);
    dp[i][0] %= 1000000007;
    dp[i][1] += dp[i - 1][0] * max(0, cnt);
    dp[i][1] %= 1000000007;
    dp[i][1] += dp[i - 1][1] * max(0, cnt - 1);
    dp[i][1] %= 1000000007;
  }
  cout << dp[k][1] << endl;
  return 0;
}
