#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
const int Maxn = 1010;
int f[110000], g[110000];
int a[Maxn * 2], b[Maxn * 2];
int sum[110000];
char st[Maxn];
int n, m, cnt;
bool Check(int s) {
  for (int i = 0; i < n; ++i)
    if (a[s + i] != b[i]) return false;
  return true;
}
void Update(int &x, int y) {
  if (y < 0) y += mo;
  x += y;
  if (x >= mo) x -= mo;
}
int main() {
  scanf("%s", st);
  n = strlen(st);
  for (int i = 0; i < n; ++i) a[i] = st[i] - 'a';
  for (int i = 0; i < n; ++i) a[i + n] = a[i];
  scanf("%s", st);
  for (int i = 0; i < n; ++i) b[i] = st[i] - 'a';
  scanf("%d", &m);
  sum[0] = 1;
  for (int i = 1; i <= m; ++i) sum[i] = (long long)sum[i - 1] * (n - 1) % mo;
  f[0] = 0;
  f[1] = 1;
  for (int i = 2; i <= m; ++i) {
    f[i] = sum[i - 1] - f[i - 1];
    if (f[i] < 0) f[i] += mo;
  }
  g[0] = 1;
  g[1] = 0;
  for (int i = 2; i <= m; ++i) {
    g[i] = sum[i - 1] - g[i - 1];
    if (g[i] < 0) g[i] += mo;
  }
  if (!m) {
    if (Check(0))
      printf("1\n");
    else
      printf("0\n");
    return 0;
  }
  int ans = 0;
  if (Check(0)) Update(ans, g[m]);
  for (int i = 1; i < n; ++i)
    if (Check(i)) Update(ans, f[m]);
  printf("%d\n", ans);
  return 0;
}
