#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000000 + 7);
inline void update(int &a, const int &b) { ((a += b) >= MOD) ? (a -= MOD) : 0; }
int gcd(const int &a, const int &b) { return b == 0 ? a : gcd(b, a % b); }
inline int Mult(const int &a, const int &b) { return (a * 1LL) * b % MOD; }
void exgcd(const int &a, const int &b, int &x, int &y) {
  if (b == 0)
    x = 1, y = 0;
  else
    exgcd(b, a % b, y, x), y -= x * (a / b);
}
inline int inverse(const int &a) {
  int invx, invy;
  exgcd(a, MOD, invx, invy);
  return (invx % MOD + MOD) % MOD;
}
const int Max_N(300050);
const int Max_AC(600050);
int N, A, C, CA, CB, DA, DB, Com[Max_AC], power[Max_AC];
int LC, LD;
char SC[Max_N], SD[Max_N];
void init() {
  scanf("%s", SC + 1), LC = strlen(SC + 1);
  for (int i = 1; i <= LC; ++i)
    CA += (SC[i] == 'A'), CB += (SC[i] == 'B'), A += (SC[i] == '?');
  scanf("%s", SD + 1), LD = strlen(SD + 1);
  for (int i = 1; i <= LD; ++i)
    DA += (SD[i] == 'A'), DB += (SD[i] == 'B'), C += (SD[i] == '?');
  Com[0] = 1;
  for (int i = 1; i <= A + C; ++i)
    Com[i] = Mult(Com[i - 1], Mult(A + C - i + 1, inverse(i)));
  scanf("%d", &N);
  power[0] = 1;
  for (int i = 1; i <= max(N, A + C); ++i) power[i] = Mult(power[i - 1], 2);
}
namespace equal {
bool Prime[Max_N];
int ps, P[Max_N], phi[Max_N], Sum[Max_N];
void prepare() {
  memset(Prime, true, sizeof(Prime)), Prime[0] = Prime[1] = false, phi[1] = 1;
  for (int i = 2; i <= N; ++i) {
    if (Prime[i]) P[++ps] = i, phi[i] = i - 1;
    for (int j = 1; j <= ps && i * P[j] <= N; ++j) {
      Prime[i * P[j]] = false;
      if (i % P[j])
        phi[i * P[j]] = phi[i] * phi[P[j]];
      else {
        phi[i * P[j]] = phi[i] * P[j];
        break;
      }
    }
  }
  Sum[1] = 1;
  for (int i = 2; i <= N; ++i) Sum[i] = (Sum[i - 1] + Mult(phi[i], 2)) % MOD;
}
int work() {
  int Ret(0);
  for (int d = 1; d <= N; ++d) update(Ret, Mult(power[d], Sum[N / d]));
  return Ret;
}
}  // namespace equal
namespace difft {
int Pre[Max_N];
void prepare() {
  for (int i = 1; i <= N; ++i) Pre[i] = (Pre[i - 1] + power[i]) % MOD;
}
}  // namespace difft
void work() {
  equal::prepare();
  difft::prepare();
  int Ans(0);
  for (int DS = 0 - C, DT, val, ds, dt; DS <= A - 0; ++DS) {
    if (!(C + DS >= 0 && C + DS <= A + C)) continue;
    val = Com[C + DS];
    DT = C - A + DS;
    ds = DS + CA - DA;
    dt = DT + DB - CB;
    if (ds == 0 && dt == 0) update(Ans, Mult(val, equal::work()));
    if (ds > 0 && dt > 0)
      update(Ans, Mult(val, difft::Pre[N / (max(+ds, +dt) / gcd(+ds, +dt))]));
    if (ds < 0 && dt < 0)
      update(Ans, Mult(val, difft::Pre[N / (max(-ds, -dt) / gcd(-ds, -dt))]));
  }
  int cnt(0);
  if (LC != LD) goto loop;
  for (int i = 1; i <= LC; ++i) {
    if (SC[i] == 'A' && SD[i] == 'B') goto loop;
    if (SC[i] == 'B' && SD[i] == 'A') goto loop;
    if (SC[i] == '?' && SD[i] == '?') ++cnt;
  }
  Ans = ((Ans - Mult(power[cnt], equal::work())) % MOD + MOD) % MOD;
  update(Ans, Mult(power[cnt], Mult(difft::Pre[N], difft::Pre[N])));
loop:
  printf("%d", Ans);
}
int main() {
  init();
  work();
  return 0;
}
