#include <bits/stdc++.h>
using namespace std;
const long long mxn = 4e4 + 123;
const long long inf = 1e9 + 7;
const long long mod = 998244353;
long long a[mxn], p[mxn], l[mxn], u[mxn], uu[mxn], dp[mxn], d[mxn];
vector<int> v;
void rec(int x, int y, int p) {
  if (x == y) {
    v.push_back(p);
    return;
  }
  rec(x, y + 1, p * 10 + 4);
  rec(x, y + 1, p * 10 + 7);
}
int main() {
  string l, r;
  cin >> l >> r;
  int k;
  cin >> k;
  int x = 0;
  int y = l.size();
  while (y--) {
    string p = "";
    p = l[l.size() - 1];
    p += l.substr(0, l.size() - 1);
    if (p == r) x++;
    l = p;
  }
  if (l == r)
    dp[0] = 1, d[0] = 0;
  else
    dp[0] = 0, d[0] = 1;
  for (int i = 1; i <= k; i++)
    dp[i] = dp[i - 1] * (x - 1) + d[i - 1] * x,
    d[i] = dp[i - 1] * (l.size() - x) + d[i - 1] * (l.size() - x - 1),
    dp[i] %= inf, d[i] %= inf;
  cout << dp[k];
  return 0;
}
