#include <bits/stdc++.h>
using namespace std;
long long m = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long c[n + 1];
  c[n] = 0;
  long long prod = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'c') {
      c[i] = (prod + c[i + 1]) % m;
    } else if (s[i] == '?') {
      c[i] = (3 * c[i + 1] + prod) % m;
      prod = (prod * 3) % m;
    } else {
      c[i] = c[i + 1];
    }
  }
  long long bc[n + 1];
  bc[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'b') {
      bc[i] = (c[i + 1] + bc[i + 1]) % m;
    } else if (s[i] == '?') {
      bc[i] = (3 * bc[i + 1] + c[i + 1]) % m;
    } else {
      bc[i] = bc[i + 1];
    }
  }
  long long a[n + 1];
  a[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'a') {
      a[i] = (bc[i + 1] + a[i + 1]) % m;
    } else if (s[i] == '?') {
      a[i] = (3 * a[i + 1] + bc[i + 1]) % m;
    } else {
      a[i] = a[i + 1];
    }
  }
  cout << a[0] << endl;
  return 0;
}
