#include <bits/stdc++.h>
using namespace std;
int readint() {
  char c;
  while (c = getchar(), (c < '0' || c > '9') && c != '-')
    ;
  bool flag = (c == '-');
  if (flag) c = getchar();
  int x = 0;
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  return flag ? -x : x;
}
const int maxn = 1000005;
const int mod = 1e9 + 7;
char c1[maxn], c2[maxn];
int k, l, r, n, A, B;
string a, b;
int z[maxn];
class matrix {
 public:
  long long m[2][2];
  matrix(int init = 1) {
    for (int(i) = 0; (i) < 2; i++)
      for (int(j) = 0; (j) < 2; j++)
        if (i == j)
          m[i][j] = init;
        else
          m[i][j] = 0;
  }
  matrix operator*(const matrix &b) const {
    matrix c(0);
    for (int(i) = 0; (i) < 2; i++)
      for (int(j) = 0; (j) < 2; j++)
        for (int(k) = 0; (k) < 2; k++) {
          c.m[i][j] += (m[i][k] * b.m[k][j]) % mod;
          c.m[i][j] %= mod;
        }
    return c;
  }
  void debug() {
    for (int(i) = 0; (i) < 2; i++) {
      for (int(j) = 0; (j) < 2; j++) printf("%I64d ", m[i][j]);
      puts("");
    }
  }
};
void prefix(string s) {
  for (int(k) = 1; (k) <= s.size() - 1; k++) {
    if (k >= r) {
      for (int(i) = 0; (i) < s.size(); i++)
        if (s[i] == s[k + i])
          z[k]++;
        else
          break;
      if (z[k]) l = k;
      r = k + z[k] - 1;
    } else {
      if (k > l && k < r && z[k - l] < r - k)
        z[k] = z[k - l];
      else {
        z[k] = r - k;
        for (int i = r - k; i < s.size(); i++)
          if (s[i] == s[i + k])
            z[k]++;
          else
            break;
        if (z[k]) l = k, r = k + z[k] - 1;
      }
    }
  }
}
matrix quick_pow(long long power, matrix x) {
  matrix res;
  while (power) {
    if (power & 1) res = res * x;
    x = x * x;
    power >>= 1;
  }
  return res;
}
int main() {
  scanf("%s%s", &c1, &c2);
  k = readint();
  a = c1;
  b = c2;
  const int n = a.size();
  prefix(b + a + a);
  for (int i = n; i < n * 2; i++)
    if (z[i] >= n) A++;
  B = n - A;
  matrix org;
  org.m[0][0] = A - 1;
  org.m[0][1] = A;
  org.m[1][0] = B;
  org.m[1][1] = B - 1;
  matrix ans = quick_pow((long long)k, org);
  matrix other(0);
  other.m[0][0] = (a == b);
  other.m[1][0] = (a != b);
  ans = ans * other;
  printf("%I64d", ans.m[0][0]);
  return 0;
}
