#include <bits/stdc++.h>   using namespace std;   const int N = 1000, MD = 1000000007;   char aa[N + 1], bb[N + 1], cc[N * 3];   int zz[N * 3];   void mult(int aa[][2], int bb[][2], int cc[][2]) {     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) {         long long c = 0;         for (int k = 0; k < 2; k++) c += (long long)aa[i][k] * bb[k][j];         cc[i][j] = c % MD;       }   }   void power(int aa[][2], int pp[][2], int tt[][2], int k) {     if (k == 0) {       pp[0][0] = 1, pp[0][1] = 0;       pp[1][0] = 0, pp[1][1] = 1;       return;     }     if (k & 1) {       power(aa, pp, tt, k >> 1);       mult(pp, pp, tt);       mult(tt, aa, pp);     } else {       power(aa, tt, pp, k >> 1);       mult(tt, tt, pp);     }   }   int main() {     int k;     cin >> aa >> bb >> k;     int n = strlen(aa);     for (int i = 0; i < n; i++) {       cc[i] = bb[i];       cc[n + i] = cc[n + n + i] = aa[i];     }     for (int l = 0, r = 0, i = 1; i < n * 3; i++)       if (i + zz[i - l] < r)         zz[i] = zz[i - l];       else {         l = i;         if (r < l) r = l;         while (r < n * 3 && cc[r] == cc[r - l]) r++;         zz[i] = r - l;       }     int a = 0;     for (int i = n; i < n + n; i++)       if (zz[i] >= n) a++;     int b = n - a;     int aa[2][2], pp[2][2], tt[2][2];     aa[0][0] = a - 1, aa[0][1] = a;     aa[1][0] = b, aa[1][1] = b - 1;     power(aa, pp, tt, k);     int ans = zz[n] >= n ? pp[0][0] : pp[0][1];     if (ans < 0) ans += MD;     cout << ans <<   n ;     return 0;   }   