#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 100;
const int mod = 1e9 + 7;
long long cnt1 = 1, cnt2, cnt3, cnt4;
long long n;
char s[MAX];
int main() {
  while (cin >> n) {
    cnt1 = 1;
    cnt2 = cnt3 = cnt4 = 0;
    cin >> s + 1;
    for (int i = 1; i <= n; i++) {
      if (s[i] == 'a') {
        cnt2 = cnt2 + cnt1 % mod;
        cnt2 %= mod;
      } else if (s[i] == 'b') {
        cnt3 += cnt2;
        cnt3 %= mod;
      } else if (s[i] == 'c') {
        cnt4 += cnt3;
        cnt4 %= mod;
      } else if (s[i] == '?') {
        cnt4 = 3 * cnt4 + cnt3, cnt4 %= mod;
        cnt3 = 3 * cnt3 + cnt2, cnt3 %= mod;
        cnt2 = 3 * cnt2 + cnt1, cnt2 %= mod;
        cnt1 *= 3, cnt1 %= mod;
      } else {
        cout << "WRONG INPUT" << endl;
      }
    }
    cout << cnt4 % mod << endl;
  }
  return 0;
}
