#include <bits/stdc++.h>
using namespace std;
const int maxk = 1e5 + 1, mod = 1e9 + 7;
string s, t;
long long dp[maxk][2];
int k;
int main() {
  cin >> s >> t;
  scanf("%d", &k);
  dp[0][!(s == t)] = 1;
  int lt = t.length();
  int x = 0;
  for (int i = 0; i < lt; i++) {
    if (s[i] == t[0]) {
      for (int j = 1; j < lt; j++) {
        if (s[(i + j) % lt] != t[j]) goto part1;
      }
      x++;
    }
  part1:;
  }
  for (int i = 1; i <= k; i++) {
    dp[i][0] = (x * dp[i - 1][1] + (x - 1) * dp[i - 1][0]) % mod;
    dp[i][1] = ((lt - x) * dp[i - 1][0] + (lt - x - 1) * dp[i - 1][1]) % mod;
  }
  printf("%lld", dp[k][0]);
  return 0;
}
