#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string a, s;
  int k;
  cin >> a >> s >> k;
  int x = 0;
  int l = a.length();
  long long int dp1[100005], dp2[100005];
  int g = 0, b = 0;
  if (a == s)
    g++;
  else
    b++;
  dp1[0] = g;
  dp2[0] = b;
  for (int i = 1; i < l; i++) {
    int cnt = 0;
    for (int j = 0; j < l; j++)
      if (a[(i + j) % l] == s[j]) cnt++;
    if (cnt == l)
      g++;
    else
      b++;
  }
  for (int i = 1; i <= k; i++) {
    dp1[i] = (dp1[i - 1] * (g - 1) + dp2[i - 1] * g) % mod;
    dp2[i] = (dp1[i - 1] * (b) + dp2[i - 1] * (b - 1)) % mod;
  }
  cout << dp1[k];
  return 0;
}
