#include <bits/stdc++.h>
using namespace std;
int mod = (int)1e9 + 7;
int n;
char s[2 * (int)1e5 + 5];
int aCnt[2 * (int)1e5 + 5];
int cCnt[2 * (int)1e5 + 5];
int qCntlr[2 * (int)1e5 + 5];
int qCntrl[2 * (int)1e5 + 5];
long long modAdd(long long a, long long b) {
  long long ret = a + b;
  if (ret >= mod) ret -= mod;
  return ret;
}
long long modMul(long long a, long long b) { return (a * b) % mod; }
long long bigMod(long long b, long long p) {
  long long ret = 1;
  while (p > 0) {
    if (p & 1) ret = modMul(ret, b);
    p >>= 1;
    b = modMul(b, b);
  }
  return ret;
}
int main() {
  scanf("%d %s", &n, s + 1);
  for (int i = 1; i <= n; i++) {
    aCnt[i] += aCnt[i - 1] + (s[i] == 'a');
    qCntlr[i] += qCntlr[i - 1] + (s[i] == '?');
  }
  for (int i = n; i >= 1; i--) {
    cCnt[i] += cCnt[i + 1] + (s[i] == 'c');
    qCntrl[i] += qCntrl[i + 1] + (s[i] == '?');
  }
  long long res = 0;
  for (int i = n - 1; i > 1; i--) {
    if (s[i] == 'b') {
      long long left = modMul(aCnt[i - 1], bigMod(3, qCntlr[i - 1]));
      if (qCntlr[i - 1])
        left =
            modAdd(left, modMul(bigMod(3, qCntlr[i - 1] - 1), qCntlr[i - 1]));
      long long right = modMul(cCnt[i + 1], bigMod(3, qCntrl[i + 1]));
      if (qCntrl[i + 1])
        right =
            modAdd(right, modMul(bigMod(3, qCntrl[i + 1] - 1), qCntrl[i + 1]));
      res = modAdd(res, modMul(left, right));
    } else if (s[i] == '?') {
      long long left = modMul(aCnt[i - 1], bigMod(3, qCntlr[i - 1]));
      if (qCntlr[i - 1])
        left =
            modAdd(left, modMul(bigMod(3, qCntlr[i - 1] - 1), qCntlr[i - 1]));
      long long right = modMul(cCnt[i + 1], bigMod(3, qCntrl[i + 1]));
      if (qCntrl[i + 1])
        right =
            modAdd(right, modMul(bigMod(3, qCntrl[i + 1] - 1), qCntrl[i + 1]));
      res = modAdd(res, modMul(left, right));
    }
  }
  printf("%lld\n", res);
}
