#include <bits/stdc++.h>
using namespace std;
long long g, b, dpg[100005], dpb[100005], k;
string st, ed;
long long calg(int i);
long long calb(int i);
long long calg(int i) {
  if (dpg[i] != -1) return dpg[i];
  return dpg[i] = (g - 1) * calg(i - 1) + g * calb(i - 1);
}
long long calb(int i) {
  if (dpb[i] != -1) return dpb[i];
  return dpb[i] = (b - 1) * calb(i - 1) + b * calg(i - 1);
}
void cnt() {
  int i;
  g = b = 0;
  if (st == ed) {
    dpg[0] = 1;
    dpb[0] = 0;
  } else {
    dpb[0] = 1;
    dpg[0] = 0;
  }
  for (i = 0; i < st.size(); ++i) {
    st = st.back() + st;
    st.pop_back();
    if (st == ed)
      ++g;
    else
      ++b;
  }
}
int main() {
  cin >> st >> ed >> k;
  cnt();
  int i;
  for (i = 1; i <= k; ++i) {
    dpg[i] =
        (((g - 1) * dpg[i - 1]) % 1000000007 + (g * dpb[i - 1]) % 1000000007) %
        1000000007;
    dpb[i] =
        (((b - 1) * dpb[i - 1]) % 1000000007 + (b * dpg[i - 1]) % 1000000007) %
        1000000007;
  }
  cout << dpg[k] << endl;
  return 0;
}
