#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 23;
const long long INF = 1e18 * 9;
const long long M = 3000 + 3;
const long long mod = 1e9 + 7;
long long dix[] = {-1, 1, 0, 0, -1, -1, 1, 1};
long long diy[] = {0, 0, 1, -1, 1, -1, 1, -1};
map<long long, long long> mp, mp1;
string s, ss;
long long n, m, x, y, k, a[N], dp[4];
vector<long long> ve;
void solve() {
  long long ans = 0, ans2 = 0, f = -1, pos = 1, mx = 0;
  cin >> n >> s;
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == 'a') dp[0] = (dp[0] + pos) % mod;
    if (s[i] == 'b') dp[1] = (dp[1] + dp[0]) % mod;
    if (s[i] == 'c') dp[2] = (dp[2] + dp[1]) % mod;
    if (s[i] == '?') {
      dp[2] = (dp[2] * 3 % mod + dp[1]) % mod;
      dp[1] = (dp[1] * 3 % mod + dp[0]) % mod;
      dp[0] = (dp[0] * 3 % mod + pos) % mod;
      pos = (pos * 3) % mod;
    }
  }
  cout << dp[2] << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  solve();
}
