#include <bits/stdc++.h>
using namespace std;
const int V = 1200;
const int P = 1000000007;
char s1[V], s2[V];
bool can[V];
int n, i, j, K;
int main() {
  while (~scanf("%s%s", s1, s2)) {
    scanf("%d", &K);
    n = strlen(s1);
    memset(can, 0, sizeof(can));
    for (i = 0; i < n; i++) {
      bool sm = true;
      for (j = 0; j < n; j++)
        if (s1[(i + j) % n] != s2[j]) {
          sm = false;
          break;
        }
      if (sm) can[i] = 1;
    }
    if (K == 0) {
      printf("%d\n", can[0]);
      continue;
    }
    int x = 0, y = 1;
    for (i = 0; i < K - 1; i++) {
      int tx = (long long)(n - 1) * y % P;
      int ty = (x + (long long)(n - 2) * y) % P;
      x = tx, y = ty;
    }
    int ans = (long long)can[0] * x % P;
    for (i = 1; i < n; i++) ans = (ans + (long long)can[i] * y) % P;
    cout << ans << endl;
  }
}
