#include <bits/stdc++.h>
using namespace std;
const long long maxm = 2e5 + 5;
const long long mod = 1e9 + 7;
char s[maxm];
long long p3[maxm];
long long lx[maxm], rx[maxm];
long long ly[maxm], ry[maxm];
long long n;
void init() {
  p3[0] = 1;
  for (long long i = 1; i < maxm; i++) p3[i] = 1ll * p3[i - 1] * 3 % mod;
}
signed main() {
  init();
  cin >> n;
  scanf("%s", s + 1);
  for (long long i = 1; i <= n; i++) {
    lx[i] = lx[i - 1];
    ly[i] = ly[i - 1];
    if (s[i] == 'a')
      lx[i]++;
    else if (s[i] == '?')
      ly[i]++;
  }
  for (long long i = n; i >= 1; i--) {
    rx[i] = rx[i + 1];
    ry[i] = ry[i + 1];
    if (s[i] == 'c')
      rx[i]++;
    else if (s[i] == '?')
      ry[i]++;
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (s[i] == 'b' || s[i] == '?') {
      long long L = 0;
      L += p3[ly[i - 1]] * lx[i - 1] % mod;
      if (ly[i - 1]) L += p3[ly[i - 1] - 1] * ly[i - 1] % mod;
      long long R = 0;
      R += p3[ry[i + 1]] * rx[i + 1] % mod;
      if (ry[i + 1]) R += p3[ry[i + 1] - 1] * ry[i + 1] % mod;
      ans = (ans + L * R) % mod;
    }
  }
  cout << ans << endl;
  return 0;
}
