#include <bits/stdc++.h>
using namespace std;
const int N = 400005, P = 1000000007;
using ll = long long;
char a[N], b[N];
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
ll qpow(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % P;
    a = a * a % P;
    b >>= 1;
  }
  return ret;
}
ll pw[N], fac[N * 2], ifac[N * 2];
ll C(int n, int m) {
  return n < m || m < 0 ? 0 : fac[n] * ifac[m] % P * ifac[n - m] % P;
}
int n;
ll df[N], mu[N];
ll calc(int da, int db) {
  if (da == db && !da) return df[n];
  if ((da >= 0 && db >= 0) || (da <= 0 && db <= 0)) return 0;
  da = abs(da);
  db = abs(db);
  if (da == db) return pw[n + 1] - 2;
  int gg = gcd(da, db);
  return pw[n / max(da / gg, db / gg) + 1] - 2;
}
int pr[N];
bool vis[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> (a + 1) >> (b + 1);
  int la = strlen(a + 1), lb = strlen(b + 1);
  cin >> n;
  fac[0] = 1;
  for (int i = 1; i <= max(la, lb) * 2; i++) fac[i] = fac[i - 1] * i % P;
  ifac[max(la, lb) * 2] = qpow(fac[max(la, lb) * 2], P - 2);
  for (int i = max(la, lb) * 2; i > 0; --i) ifac[i - 1] = ifac[i] * i % P;
  mu[1] = 1;
  int ptr = 0;
  pw[1] = 2;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) pr[ptr++] = i, mu[i] = P - 1;
    for (int j = 0; j < ptr; j++) {
      int tmp = i * pr[j];
      if (tmp > n) break;
      vis[tmp] = 1;
      if (i % pr[j] == 0) break;
      mu[tmp] = (P - mu[i]) % P;
    }
    pw[i] = (pw[i - 1] << 1) % P;
  }
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j += i) df[j] = (df[j] + pw[i] * mu[j / i]) % P;
  pw[n + 1] = (pw[n] << 1) % P;
  for (int i = 1; i <= n; i++)
    df[i] = (df[i - 1] + df[i] * (n / i) % P * (n / i) % P) % P;
  int p = 0, q = 0, da = 0, db = 0;
  for (int i = 1; i <= la; i++)
    p += (a[i] == '?'), da += (a[i] == 'A'), db += (a[i] == 'B');
  for (int i = 1; i <= lb; i++)
    q += (b[i] == '?'), da -= (b[i] == 'A'), db -= (b[i] == 'B');
  ll ans = 0;
  for (int i = -max(p, q); i <= max(p, q); i++)
    if (C(p + q, p - i))
      ans = (ans + C(p + q, p - i) * calc(da + i, db + p - q - i)) % P;
  if (la == lb) {
    for (int i = 1; i <= la; i++)
      if (a[i] != b[i] && a[i] != '?' && b[i] != '?') {
        cout << ans << endl;
        return 0;
      }
    ll tt = 1;
    for (int i = 1; i <= la; i++)
      if (a[i] == '?' && b[i] == '?') tt = (tt << 1) % P;
    ans =
        (ans - df[n] * tt % P + (pw[n + 1] - 2) * (pw[n + 1] - 2) % P * tt) % P;
    ans = (ans % P + P) % P;
  }
  cout << ans << endl;
  return 0;
}
