#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
void solve() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int dp[n + 1][3];
  memset(dp, 0, sizeof(dp));
  long long int st = 1;
  for (long long int i = 0; i < n; i++) {
    if (i > 0) {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = dp[i - 1][1];
      dp[i][2] = dp[i - 1][2];
    }
    if (s[i] == 'c')
      dp[i][2] += dp[i][1];
    else if (s[i] == 'b')
      dp[i][1] += dp[i][0];
    else if (s[i] == 'a')
      dp[i][0] += st;
    else {
      dp[i][2] = dp[i][2] * 3 + dp[i][1];
      dp[i][1] = dp[i][1] * 3 + dp[i][0];
      dp[i][0] = dp[i][0] * 3 + st;
      st = st * 3;
    }
    st = st % mod;
    dp[i][2] %= mod;
    dp[i][1] %= mod;
    dp[i][0] %= mod;
  }
  cout << dp[n - 1][2] << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
