#include <bits/stdc++.h>
using namespace std;
long long i, j, k, n, m, x, y, T, ans, mx, mi, cas, num, len;
bool flag;
const long long dz = 909091;
const long long dm = 1000000007;
char a[10005], b[10005];
long long ha[10005];
long long s[100005];
map<long long, long long> mp;
int main() {
  scanf("%s", &a);
  scanf("%s", &b);
  scanf("%I64d", &n);
  len = strlen(a);
  long long ta = 0;
  for (i = 0; i < len; i++) ta = (ta * dz + b[i] - '0' + 1) % dm;
  for (i = len; i < 2 * len; i++) a[i] = a[i - len];
  for (i = 0; i < len; i++) {
    ha[i] = 0;
    for (j = 0; j < len; j++) {
      ha[i] = (ha[i] * dz + a[i + j] - '0' + 1) % dm;
    }
    mp[ha[i]]++;
  }
  long long mb;
  if ((mb = mp[ta]) == 0) {
    printf("0\n");
    return 0;
  }
  s[0] = 1;
  long long sum = 0;
  for (i = 1; i <= n; i++) {
    s[i] = s[i - 1] * (len - 1) % dm;
  }
  if (ta == ha[0])
    ans = 1;
  else
    ans = 0;
  for (i = 1; i <= n; i++) {
    ans = (s[i - 1] * mb % dm - ans + dm) % dm;
  }
  printf("%I64d\n", ans);
  return 0;
}
