#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long llread() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int f[2][1010];
int main() {
  string st1, st2;
  cin >> st1 >> st2;
  if (st1.size() != st2.size()) return puts("0"), 0;
  int n = read(), m = st1.size();
  f[0][0] = 1;
  int now = 0;
  for (int i = (1); i <= (n); i++) {
    int sum = 0;
    for (int j = (0); j < (m); j++) {
      sum += f[now][j];
      if (sum >= 1000000007) sum -= 1000000007;
    }
    for (int j = (0); j < (m); j++) {
      f[now ^ 1][j] = sum - f[now][j] + 1000000007;
      if (f[now ^ 1][j] >= 1000000007) f[now ^ 1][j] -= 1000000007;
    }
    now ^= 1;
  }
  int res = 0;
  for (int i = (0); i < (st1.size()); i++) {
    string st = "";
    for (int j = (1); j < (st1.size()); j++) st += st1[j];
    st += st1[0];
    st1 = st;
    if (st == st2) {
      res += f[now][(i + 1) % m];
      if (res >= 1000000007) res -= 1000000007;
    }
  }
  printf("%d\n", res);
  return 0;
}
