#include <bits/stdc++.h>
using namespace std;
string s;
void sdvig() {
  char x = s[0];
  s.erase(0, 1);
  s = s + (char)x;
}
vector<string> v;
string fin;
vector<int> dp[4];
int k, base = 1000000007;
int mod(int x) {
  if (x < 0) x += base;
  return x;
}
int main() {
  cin >> s >> fin;
  cin >> k;
  v.push_back(s);
  int l = s.length();
  for (int i = 1; i < l; i++) {
    sdvig();
    v.push_back(s);
  }
  sdvig();
  sort(v.begin(), v.end());
  vector<int> gvv(1100);
  dp[1] = gvv;
  dp[2] = dp[1];
  int sum1 = 0, sum2 = 0;
  int g;
  for (int i = 0; i < v.size(); i++)
    if (v[i] == s) {
      dp[1][i] = 1;
      sum1++;
    }
  for (int i = 1; i <= k; i++) {
    sum2 = 0;
    for (int j = 0; j < v.size(); j++) {
      dp[2][j] = (mod(sum1 - dp[1][j])) % base;
      sum2 = (sum2 + dp[2][j]) % base;
    }
    sum1 = sum2;
    swap(dp[1], dp[2]);
  }
  int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] == fin) {
      ans = (ans + dp[1][i]) % base;
      break;
    }
  }
  cout << ans;
}
