#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
unsigned long long l;
string s = "acbbac";
unsigned long long f[500005][4];
unsigned long long cnt[500005];
unsigned long long mul(unsigned long long x, unsigned long long y) {
  return ((x % MOD) * (y % MOD)) % MOD;
}
unsigned long long add(unsigned long long x, unsigned long long y) {
  return ((x % MOD) + (y % MOD)) % MOD;
}
unsigned long long qp(unsigned long long a, unsigned long long n) {
  long long res = 1, bs = a;
  while (n > 0) {
    if (n & 1) res = mul(res, bs);
    bs = mul(bs, bs);
    n >>= 1;
  }
  return res;
}
signed main() {
  string s;
  cin >> l;
  cin >> s;
  l = s.length();
  s = "_" + s;
  for (unsigned long long i = 1; i <= l; i++) {
    cnt[i] = cnt[i - 1];
    if (s[i] == '?') {
      cnt[i]++;
    }
  }
  for (unsigned long long i = 1; i <= l; i++) {
    if (s[i] != '?') {
      f[i][0] = add(f[i - 1][0], (s[i] == 'a' ? qp(3, cnt[i - 1]) : 0));
      f[i][1] = add(f[i - 1][1], (s[i] == 'b' ? f[i - 1][0] : 0));
      f[i][2] = add(f[i - 1][2], (s[i] == 'c' ? f[i - 1][1] : 0));
    } else {
      f[i][0] = add(3 * f[i - 1][0], qp(3, cnt[i - 1]));
      f[i][1] = add(3 * f[i - 1][1], f[i - 1][0]);
      f[i][2] = add(3 * f[i - 1][2], f[i - 1][1]);
    }
  }
  printf("%d\n", f[l][2] % MOD);
}
