#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long f[1000010], ans1 = 0, k, g[1000010], u[1000010], h[1000010],
                      in[1000010], lim[1000010], v[1000010], n;
char s1[1000010], s2[1000010];
long long C(long long x, long long y) {
  return f[x] * g[y] % mod * g[x - y] % mod;
}
long long lily1(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) {
      ans *= x;
      ans %= mod;
    }
    x *= x;
    x %= mod;
    y >>= 1;
  }
  return ans;
}
long long lily(long long x) {
  if (v[x]) return u[x];
  if (x == 1) return u[x] = 1;
  v[x] = 1;
  long long q = x / h[x];
  if (q % h[x] == 0) return u[x] = 0;
  return lily(q) * (-1);
}
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
void js1() {
  long long i, d;
  for (i = 1; i <= n; i++) {
    long long p = n / i;
    p *= p;
    p %= mod;
    for (d = 1; d * d <= i; d++)
      if (i % d == 0) {
        ans1 += lim[d] * u[i / d] * p;
        ans1 = (ans1 + mod) % mod;
        if (d * d != i) {
          ans1 += lim[i / d] * u[d] * p;
          ans1 = (ans1 + mod) % mod;
        }
      }
  }
}
long long F(long long a, long long b) {
  if (a == b && a == 0) return ans1;
  if (a * b >= 0) return 0;
  a = abs(a);
  b = abs(b);
  if (a == b) return ((lim[n + 1] - k) * in[k - 1] + mod) % mod;
  long long q = gcd(a, b);
  long long c = max(a / q, b / q);
  long long u = n / c;
  return ((lim[u + 1] - k) * in[k - 1] + mod) % mod;
}
signed main() {
  long long i, j, ans = 0, k1;
  scanf("%s", s1);
  scanf("%s", s2);
  scanf("%lld", &n);
  k = 2;
  lim[0] = 1;
  lim[1] = k;
  in[1] = in[0] = 1;
  for (i = 2; i <= 1000000; i++)
    lim[i] = (lim[i - 1] * k) % mod,
    in[i] = in[mod % i] * (mod - mod / i) % mod;
  f[0] = 1;
  for (i = 1; i <= 1000000; i++) f[i] = f[i - 1] * i % mod;
  g[1000000] = lily1(f[1000000], mod - 2);
  for (i = 999999; i >= 0; i--) g[i] = (g[i + 1] * (i + 1)) % mod;
  for (i = 2; i <= 1000000; i++) {
    if (!h[i]) {
      for (j = i * i; j <= 1000000; j += i) h[j] = i;
    }
  }
  for (i = 1; i <= 1000000; i++) {
    if (!h[i]) h[i] = i;
    u[i] = lily(i);
  }
  js1();
  long long l1 = strlen(s1) - 1;
  long long l2 = strlen(s2) - 1;
  long long a = 0, b = 0, p = 0, q = 0;
  for (i = 0; i <= l1; i++) {
    if (s1[i] == 'A') a++;
    if (s1[i] == 'B') b++;
    if (s1[i] == '?') p++;
  }
  for (i = 0; i <= l2; i++) {
    if (s2[i] == 'A') a--;
    if (s2[i] == 'B') b--;
    if (s2[i] == '?') q++;
  }
  long long flag = 1;
  for (i = 0; i <= l1; i++)
    if (s1[i] != s2[i] && s1[i] != '?' && s2[i] != '?') flag = 0;
  for (k1 = -q; k1 <= p; k1++) {
    ans += F(a + k1, b + p - q - k1) * C(p + q, p - k1) % mod;
    ans %= mod;
  }
  if (l1 == l2 && flag) {
    long long tot = 1;
    for (i = 0; i <= l1; i++)
      if (s1[i] == '?' && s2[i] == '?') {
        tot *= 2;
        tot %= mod;
      }
    ans -= tot * ans1 % mod;
    ans += mod;
    ans %= mod;
    long long ret = (lim[n + 1] - k) * in[k - 1] % mod;
    ans += ret * ret % mod * tot % mod;
    (ans += mod) %= mod;
  }
  printf("%lld\n", ans);
}
