#include <bits/stdc++.h>
using namespace std;
long long dp[2][100010];
long long MOD = 1000000007;
int main() {
  string s1, s2;
  int k;
  while (cin >> s1 >> s2 >> k) {
    s1 = s1 + s1;
    int cntS = 0, cntD = 0;
    for (int i = 0; i < s2.size(); ++i)
      if (s1.substr(i, s2.size()) == s2)
        cntS++;
      else
        cntD++;
    if (s1.substr(0, s2.size()) == s2)
      dp[0][0] = 1, dp[1][0] = 0;
    else
      dp[0][0] = 0, dp[1][0] = 1;
    for (int i = 1; i <= k; ++i) {
      dp[0][i] = dp[0][i - 1] * (cntS - 1) + dp[1][i - 1] * (cntS);
      dp[1][i] = dp[0][i - 1] * (cntD) + dp[1][i - 1] * (cntD - 1);
      dp[0][i] %= MOD;
      dp[1][i] %= MOD;
    }
    cout << dp[0][k] << endl;
  }
  return 0;
}
