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