#include <bits/stdc++.h>
using namespace std;
string getLine(istream& stream) {
  string res;
  getline(stream, res);
  return res;
}
vector<string> getLineFields(istream& stream) {
  string line = getLine(stream);
  stringstream str;
  str << line;
  vector<string> fields;
  string temp;
  while (str >> temp) {
    fields.push_back(temp);
  }
  return fields;
}
template <typename T>
T str2type(string a) {
  stringstream t;
  t << a;
  T b;
  t >> b;
  return b;
}
struct good {
  int a;
  int b;
  int c;
};
int diff(string& s, string& s1) {
  string ss = s + s;
  set<string> sm;
  for (int i = 0; i < s.length(); ++i) sm.insert(ss.substr(i, s.length()));
  if (sm.find(s1) == sm.end()) return -1;
  return sm.size();
}
int main() {
  long long MOD = 1000000007;
  string s1, s2;
  cin >> s1 >> s2;
  string ss = s2 + s2;
  int k;
  cin >> k;
  pair<long long, long long> f = make_pair(1, 0);
  for (int i = 0; i < k; ++i) {
    long long temp = f.first;
    f.first = f.second * (s1.length() - 1) % MOD;
    f.second = (temp + f.second * (s1.length() - 2)) % MOD;
  }
  long long res = 0;
  for (int i = 0; i < s1.length(); ++i)
    if (ss.substr(i, s1.length()) == s1) {
      res += ((i == 0) ? f.first : f.second) % MOD;
    }
  cout << res % MOD;
  return 0;
}
