#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MAXN = 200010;
const int MOD = 1000000007;
LL a[MAXN], ab[MAXN];
LL qa[MAXN], qab[MAXN], qqab[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int sum = 0;
  for (int i = 0; i < n; ++i) sum += (s[i] == '?');
  vector<LL> p3{1};
  for (int i = 1; i <= sum; ++i) p3.push_back(p3.back() * 3 % MOD);
  LL ans = 0;
  int k = 0;
  for (int i = 0; i < s.size(); ++i) {
    a[i + 1] = a[i];
    ab[i + 1] = ab[i];
    qa[i + 1] = qa[i];
    qab[i + 1] = qab[i];
    qqab[i + 1] = qqab[i];
    if (s[i] == 'a') {
      ++a[i + 1];
    }
    if (s[i] == 'b') {
      ab[i + 1] = (ab[i + 1] + a[i]) % MOD;
      qab[i + 1] = (qab[i + 1] + qa[i]) % MOD;
    }
    if (s[i] == 'c') {
      ans = (ans + ab[i] * p3[sum]) % MOD;
      if (qab[i] > 0) {
        ans = (ans + qab[i] * p3[sum - 1]) % MOD;
      }
      if (qqab[i] > 0) {
        ans = (ans + qqab[i] * p3[sum - 2]) % MOD;
      }
    }
    if (s[i] == '?') {
      ++qa[i + 1];
      qab[i + 1] = (qab[i + 1] + a[i]) % MOD;
      qqab[i + 1] = (qqab[i + 1] + qa[i]) % MOD;
      ans = (ans + ab[i] * p3[sum - 1]) % MOD;
      if (qab[i] > 0) {
        ans = (ans + qab[i] * p3[sum - 2]) % MOD;
      }
      if (qqab[i] > 0) {
        ans = (ans + qqab[i] * p3[sum - 3]) % MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
