#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5, mod = 1e9 + 7;
long long n, ans, cases = 1, a[maxn + 1], ab[maxn + 1];
char s[maxn + 1];
int main() {
  scanf("%lld%s", &n, s + 1);
  for (int i = 1; i <= n; ++i) {
    a[i] = (a[i - 1] + (s[i] == 'a') * cases) % mod;
    ab[i] = (ab[i - 1] + a[i - 1] * (s[i] == 'b')) % mod;
    ans = (ans + ab[i - 1] * (s[i] == 'c')) % mod;
    if (s[i] == '?') {
      a[i] = (a[i - 1] * 3 + cases) % mod;
      ab[i] = (ab[i - 1] * 3 + a[i - 1]) % mod;
      ans = (ans * 3 + ab[i - 1]) % mod;
      cases = cases * 3 % mod;
    }
  }
  printf("%lld", ans);
  return 0;
}
