#include <bits/stdc++.h>
using namespace std;
inline void add(long long& x, long long y) { x = (x + y) % 1000000007; }
inline void multi(long long& x, long long y) { x = (x * y) % 1000000007; }
int n;
char str[200001];
long long pre_a[200001], pre_ab[200001];
long long threePow[200001];
int main() {
  cin >> n;
  cin.ignore();
  int qm = 0;
  for (int i = 0; i < n; ++i) {
    cin >> str[i];
    if (str[i] == '?') qm++;
  }
  long long cnt = 0;
  for (int i = 0; i < n; ++i) {
    pre_a[i] = cnt;
    if (str[i] == 'a')
      cnt += 3;
    else if (str[i] == '?')
      cnt++;
  }
  cnt = 0;
  for (int i = 0; i < n; ++i) {
    pre_ab[i] = cnt;
    if (str[i] == 'b') {
      cnt += 3 * pre_a[i];
    } else if (str[i] == '?')
      cnt += pre_a[i];
  }
  cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (str[i] == 'c')
      cnt += pre_ab[i] * 3;
    else if (str[i] == '?')
      cnt += pre_ab[i];
  }
  qm -= 3;
  if (qm < 0) {
    for (int i = 0; i > qm; --i) {
      cnt /= 3;
    }
  } else {
    for (int i = 0; i < qm; ++i) {
      multi(cnt, 3);
    }
  }
  cnt %= 1000000007;
  cout << cnt << endl;
  return 0;
}
