#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const int mod = 1e9 + 7;
long long fa, fb, fc, f0;
int n;
char s[N];
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  f0 = 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'a') {
      fa = (fa + f0) % mod;
    }
    if (s[i] == 'b') {
      fb = (fb + fa) % mod;
    }
    if (s[i] == 'c') {
      fc = (fc + fb) % mod;
    }
    if (s[i] == '?') {
      fc = (fc * 3 + fb) % mod;
      fb = (fb * 3 + fa) % mod;
      fa = (fa * 3 + f0) % mod;
      (f0 *= 3) %= mod;
    }
  }
  printf("%lld\n", fc);
}
