#include <bits/stdc++.h>
using namespace std;
long long dpa[100005];
long long dpb[100005];
int main() {
  string s, t;
  int k;
  cin >> s >> t;
  cin >> k;
  int len = s.length();
  dpa[0] = 1;
  int aa = 0;
  int bb = 0;
  for (int i = 0; i < len; i++) {
    int cnt = i;
    int f = 0;
    for (int j = 0; j < len; j++) {
      if (s[cnt] != t[j]) {
        f = 1;
        break;
      }
      cnt = (cnt + 1) % len;
    }
    if (f) {
      bb++;
    } else
      aa++;
  }
  if (aa == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (s == t) {
    dpa[0] = 1;
    dpb[0] = 0;
  } else {
    dpa[0] = 0;
    dpb[0] = 1;
  }
  for (int i = 1; i <= k; i++) {
    dpa[i] = ((1LL * dpa[i - 1] * (aa - 1)) % 1000000007 +
              (1LL * dpb[i - 1] * aa) % 1000000007) %
             1000000007;
    dpb[i] = ((1LL * dpb[i - 1] * (bb - 1)) % 1000000007 +
              (1LL * dpa[i - 1] * bb) % 1000000007) %
             1000000007;
  }
  cout << dpa[k] << endl;
}
