#include <bits/stdc++.h>
using namespace std;
long len;
string a, b;
const long long mo = 1000000007;
long long good[200001], bad[200001];
int x, y, n;
int main() {
  cin >> a >> b >> n;
  if (a.length() != b.length()) {
    cout << 0;
    return 0;
  }
  len = a.length();
  bool f;
  for (int i = 0; i < len; i++) {
    f = false;
    for (int j = 0; j < len; j++) {
      if (b[j] != b[(j + i) % len]) {
        f = true;
        break;
      }
    }
    if (f == false) {
      x++;
    } else {
      y++;
    }
  }
  if (a == b) {
    good[0] = 1;
    bad[0] = 0;
  } else {
    good[0] = 0;
    bad[0] = 1;
  }
  f = false;
  b = b + b;
  bool p;
  for (int i = 0; i < len; i++) {
    p = false;
    for (int j = 0; j < len; j++) {
      if (b[j + i] != a[j]) {
        p = true;
        break;
      }
    }
    if (p == false) {
      f = true;
      break;
    }
  }
  if (f == false) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    good[i] =
        ((good[i - 1] % mo) * ((x - 1) % mo) + (bad[i - 1] * x) % mo) % mo;
    bad[i] =
        ((good[i - 1] % mo) * (y % mo) + (bad[i - 1] % mo) * ((y - 1) % mo)) %
        mo;
  }
  for (int i = 1; i <= n; i++) {
  }
  cout << good[n] % mo;
  return 0;
}
