#include <bits/stdc++.h>
using namespace std;
int bpow(int a, int b, int m) {
  b %= m - 1;
  long long r = 1;
  for (; b; b /= 2) {
    if (b & 1) r = (r * a) % m;
    a = ((long long)(a)*a) % m;
  }
  return r;
}
const int N = 200001;
int n;
char s[N];
long long aq[N], cq[N], qq[N];
int ans = 0;
int mod = 1000000007;
int main() {
  scanf("%d\n", &n);
  gets(s);
  memset(aq, 0, N * sizeof(long long));
  memset(cq, 0, N * sizeof(long long));
  memset(qq, 0, N * sizeof(long long));
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'a') aq[i + 1]++;
    if (s[i] == 'c') cq[i + 1]++;
    if (s[i] == '?') qq[i + 1]++;
    aq[i + 1] += aq[i];
    cq[i + 1] += cq[i];
    qq[i + 1] += qq[i];
  }
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'b' || s[i] == '?') {
      long long temp1 = (aq[i] * bpow(3, qq[i], mod)) % mod;
      if (qq[i]) temp1 += (qq[i] * bpow(3, qq[i] - 1, mod)) % mod;
      long long temp2 =
          (bpow(3, qq[n] - qq[i + 1], mod) * (cq[n] - cq[i + 1])) % mod;
      if (qq[n] - qq[i + 1])
        temp2 +=
            ((qq[n] - qq[i + 1]) * bpow(3, qq[n] - qq[i + 1] - 1, mod)) % mod;
      temp1 = temp1 % mod;
      temp2 = temp2 % mod;
      ans = (ans + (temp1 * temp2) % mod) % mod;
    }
  }
  printf("%d", ans);
  return 0;
}
