#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
int f(char c) { return (int)c - 96; }
struct cmp {
  bool operator()(const int &a, const int &b) { return a > b; }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int mod = 1e9 + 7;
  long long int a[200005], ab[200005], abc[200005];
  int n;
  cin >> n;
  string s;
  cin >> s;
  s = '0' + s;
  a[1] = 0;
  if (s[1] == 'a' || s[1] == '?') {
    a[1] = 1;
  }
  ab[1] = 0;
  abc[1] = 0;
  long long int cnt = 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '?') {
      a[i] = (3 * a[i - 1] + cnt) % mod;
      ab[i] = (3 * ab[i - 1] + a[i - 1]) % mod;
      abc[i] = (3 * abc[i - 1] + ab[i - 1]) % mod;
      cnt = (3 * cnt) % mod;
    } else {
      a[i] = (a[i - 1]) % mod;
      ab[i] = (ab[i - 1]) % mod;
      abc[i] = (abc[i - 1]) % mod;
      if (s[i] == 'a') {
        a[i] = (a[i - 1] + cnt) % mod;
      } else if (s[i] == 'b') {
        ab[i] = (ab[i - 1] + a[i - 1]) % mod;
      } else if (s[i] == 'c') {
        abc[i] = (abc[i - 1] + ab[i - 1]) % mod;
      }
    }
  }
  cout << (abc[n]) % mod;
  return 0;
}
