#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 1e18;
const long long mod = 1e9 + 7;
string a, b;
int n, A, B;
long long hasha, hashb, p;
struct mat {
  long long m[3][3];
  inline void init(long long x) {
    m[1][2] = m[2][1] = 0;
    m[1][1] = m[2][2] = x;
  }
  inline mat operator*(mat x) const {
    mat res;
    res.init(0);
    for (int i = 1; i <= 2; i++)
      for (int j = 1; j <= 2; j++) {
        int sum = 0;
        for (int k = 1; k <= 2; k++) {
          sum = sum + (m[i][k] * x.m[k][j]) % mod;
          sum = sum % mod;
        }
        res.m[i][j] = sum;
      }
    return res;
  }
} c;
inline mat quick_pow(mat x, int s) {
  if (s == 0) {
    mat res;
    res.init(1);
    return res;
  }
  if (s == 1) return x;
  mat t = quick_pow(x, s / 2);
  if (s % 2 == 0)
    return t * t;
  else
    return t * t * x;
}
inline long long quick_num_pow(long long x, int s) {
  if (s == 0) return 1;
  if (s == 1) return x;
  long long t = quick_num_pow(x, s / 2);
  if (s % 2 == 0)
    return (t * t) % mod;
  else
    return (((t * t) % mod) * x) % mod;
}
int main() {
  cin >> a >> b >> n;
  hasha = a[0];
  hashb = b[0];
  p = 1;
  for (int i = 1; i < a.size(); i++) {
    hasha = hasha * 159 + (long long)a[i];
    hashb = hashb * 159 + (long long)b[i];
    p = p * 159;
  }
  for (int i = 0; i < a.size(); i++) {
    hasha = (hasha - p * a[i]) * 159 + a[i];
    if (hasha == hashb)
      A++;
    else
      B++;
  }
  if (A == 0) {
    cout << 0;
    return 0;
  }
  if (B == 0) {
    cout << quick_num_pow((long long)(A - 1), n);
    return 0;
  }
  c.m[1][1] = (long long)A - 1;
  c.m[1][2] = (long long)A;
  c.m[2][1] = (long long)B;
  c.m[2][2] = (long long)B - 1;
  mat ans = quick_pow(c, n);
  if (a == b)
    cout << ans.m[1][1];
  else
    cout << ans.m[1][2];
  return 0;
}
