#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;   void Print(int *a, int n) {     for (int i = 1; i < n; i++) printf( %d  , a[i]);     printf( %d n , a[n]);   }   int e[N], nt[N];   void Gnt(string a, int *nt) {     int k = 0, p = 0, n = (int)a.size();     nt[0] = n;     for (int i = 1; i < n; i++) {       if (i + nt[i - k] < p)         nt[i] = nt[i - k];       else {         if (i >= p) p = i;         while (p < n && a[p] == a[p - i]) p++;         nt[i] = p - i;         k = i;       }     }   }   void Exd(string a, string b, int *e, int *nt) {     int k = 0, p = 0, n = (int)a.size(), m = (int)b.size();     Gnt(b, nt);     for (int i = 0; i < n; i++) {       if (i + nt[i - k] < p)         e[i] = nt[i - k];       else {         if (i >= p) p = i;         while (p < n && p - i < m && a[p] == b[p - i]) p++;         e[i] = p - i;         k = i;       }     }   }   int cycle(string a) {     int n = a.size();     Gnt(a, nt);     int t = n;     for (int i = 1; i < n; i++)       if (i + nt[i] == n) {         t = n % i ? n : i;         break;       }     return t;   }   string a, b;   int k, dp[N][2];   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> a >> b >> k;     dp[0][a != b] = 1;     int n = (int)a.size();     a = a + a;     Exd(a, b, e, nt);     int x = 0, len = (int)b.size();     for (int i = 0; i < n; i++) {       if (e[i] >= len) x++;     }     int y = n - x;     for (int i = 1; i <= k; i++) {       dp[i][0] = (1LL * x * dp[i - 1][1] + 1LL * (x - 1) * dp[i - 1][0]) % mod;       dp[i][1] = (1LL * y * dp[i - 1][0] + 1LL * (y - 1) * dp[i - 1][1]) % mod;     }     printf( %d n , dp[k][0]);     return 0;   }   