#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
const int M = 1000000007;
int len;
int main() {
  char a[N], b[N];
  scanf("%s", (a)), scanf("%s", (b));
  len = strlen(a);
  int k;
  scanf("%d", &(k));
  unsigned long long dp[110000][2];
  dp[0][0] = 1, dp[0][1] = 0;
  for (int i(1), _h(k); i <= _h; ++i) {
    dp[i][0] = dp[i - 1][1] * (len - 1) % M;
    dp[i][1] = (dp[i - 1][1] * (len - 2) % M + dp[i - 1][0]) % M;
  }
  unsigned long long ans = 0;
  for (int p(0), _n(len); p < _n; ++p) {
    int eq = 1;
    for (int i(0), _n(len); i < _n; ++i)
      if (a[i] != b[(i + p) % len]) {
        eq = 0;
        break;
      }
    if (eq) {
      ans += dp[k][p != 0];
      ans %= M;
    }
  }
  printf("%d\n", ((int)ans));
  return 0;
}
