#include <bits/stdc++.h>
using namespace std;
int N = 1000000007;
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  int k, A = 0, B = 0, len = s1.size();
  cin >> k;
  for (int i = 0; i < s1.size(); i++) {
    bool state = true;
    for (int j = 0; j < s1.size(); j++) {
      if (s1[(i + j) % len] != s2[j]) {
        state = false;
        break;
      }
    }
    if (state) {
      A++;
    } else {
      B++;
    }
  }
  vector<long long int> dpA(k + 1), dpB(k + 1);
  if (s1 == s2) {
    dpA[0] = 1;
    dpB[0] = 0;
  } else {
    dpB[0] = 1;
    dpA[0] = 0;
  }
  for (int i = 1; i <= k; i++) {
    dpA[i] = (dpA[i - 1] * (A - 1) + dpB[i - 1] * A) % N;
    dpB[i] = (dpB[i - 1] * (B - 1) + dpA[i - 1] * B) % N;
  }
  cout << dpA[k] << endl;
}
