#include <bits/stdc++.h>
using namespace std;
void get_cuts(string a, string b, vector<int>& result) {
  for (int i = 0; i < a.size(); i++) {
    if (a.substr(i) + a.substr(0, i) == b) {
      result.push_back(i);
    }
  }
}
long long powmod(long long base, long long exp, long long m) {
  long long result = 1;
  while (exp) {
    if (exp & 1) result = (result * base) % m;
    exp >>= 1;
    base = (base * base) % m;
  }
  return result;
}
long long mod_inverse(long long a, long long m) {
  long long b = m;
  long long x, y, lastx, lasty, q, tmp;
  x = 0;
  lastx = 1;
  y = 1;
  lasty = 0;
  while (b != 0) {
    q = a / b;
    tmp = b;
    b = a % b;
    a = tmp;
    tmp = x;
    x = lastx - q * x;
    lastx = tmp;
    tmp = y;
    y = lasty - q * y;
    lasty = tmp;
  }
  while (lastx < 0) lastx += m;
  return lastx;
}
long long geo(long long n, long long k, long long m) {
  if (k == 1) return n;
  long long inv = mod_inverse(k - 1, m);
  long long res = ((powmod(k, n + 1, m) - k) * inv) % m;
  return res;
}
long long solve(int size, long long x, long long k, long long m) {
  int a = ((x + k - 1 + size) % size == (size - 1)) ? 0 : 1;
  long long l;
  int size_square = (size - 1) * (size - 1);
  if (k % 2) {
    l = (k - 1) / 2;
    return ((2 * geo(l, size_square, m) % m) - (geo(2 * l, size - 1, m) % m) +
            a + m) %
           m;
  } else {
    l = k / 2;
    return ((geo(2 * l - 1, size - 1, m) % m) -
            (2 * geo(l - 1, size_square, m) % m) - a + m) %
           m;
  }
}
long long cut(string a, string b, long long k, long long m) {
  int size = a.size();
  vector<int> cuts;
  get_cuts(a, b, cuts);
  if (k == 0) return (a == b) ? 1 : 0;
  long long res = 0;
  for (vector<int>::iterator it = cuts.begin(); it != cuts.end(); ++it)
    res = (res + solve(size, ((*it - k) + size) % size, k, m)) % m;
  return res;
}
int main() {
  string a, b;
  long long k;
  getline(cin, a);
  getline(cin, b);
  cin >> k;
  cout << cut(a, b, k, 1000000007) << endl;
}
