#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
string s1, s2, s3;
bool check[1005];
int dp[2][1005];
int main() {
  int n, k;
  cin >> s1 >> s2;
  n = s1.length();
  scanf("%d", &k);
  if (k == 0) {
    if (s1 != s2) {
      printf("0\n");
    } else {
      printf("1\n");
    }
    return 0;
  }
  for (int i = 0; i < n; i++) {
    s3 = "";
    for (int j = i; j < n; j++) {
      s3 += s1[j];
    }
    for (int j = 0; j < i; j++) {
      s3 += s1[j];
    }
    if (s2 == s3) check[i] = 1;
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 1;
  int pv = 0, nt = 1;
  for (int i = 1; i <= k; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      if (dp[pv][j] != -1) sum = (sum + dp[pv][j]) % mod;
    }
    for (int j = 0; j < n; j++) {
      if (dp[pv][j] != -1)
        dp[nt][j] = (sum - dp[pv][j] + mod) % mod;
      else
        dp[nt][j] = sum;
    }
    if (i != k) swap(pv, nt);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (check[i] && dp[nt][i] != -1) ans = (ans + dp[nt][i]) % mod;
  }
  printf("%d\n", ans);
}
