#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000 + 5;
const int N = 2e3 + 5;
const long long oo = 1e18 + 5;
const long long mod = 1e9 + 7;
void add_self(int& a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mul(int a, int b) { return 1ll * a * b % mod; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int n;
  cin >> n >> s;
  vector<int> dp(4);
  dp[0] = 1;
  for (char ch : s) {
    vector<int> new_dp = dp;
    if (ch == '?') {
      for (int& x : new_dp) {
        x = mul(x, 3);
      }
      for (int i = 1; i <= 3; ++i) {
        add_self(new_dp[i], dp[i - 1]);
      }
    } else {
      int id = ch - 'a' + 1;
      add_self(new_dp[id], dp[id - 1]);
    }
    dp = new_dp;
  }
  cout << dp[3];
  return 0;
}
