#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MOD = 1e9 + 7;
void solve(int TestCase) {
  int n;
  cin >> n;
  string s;
  cin >> s;
  auto dp = vector<ll>{1, 0, 0, 0};
  for (auto c : s) {
    auto ndp = dp;
    if (c == '?') {
      for (auto& x : ndp) x = x * 3 % MOD;
      for (auto i = 0; i < 3; ++i) ndp[i + 1] = (ndp[i + 1] + dp[i]) % MOD;
    } else {
      ndp[c - 'a' + 1] += dp[c - 'a'];
      ndp[c - 'a' + 1] %= MOD;
    }
    swap(dp, ndp);
  }
  cout << dp[3] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  for (auto i = 1; i <= t; ++i) {
    solve(i);
  }
}
