#include <bits/stdc++.h>
using namespace std;
template <class T>
long long size(const T& x) {
  return x.size();
}
#pragma GCC optimize("Ofast")
template <class T>
T smod(T a, T b) {
  return (a % b + b) % b;
}
long long pw(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2) res = (res * a) % 1000000007;
    b /= 2;
    a = a * a % 1000000007;
  }
  return res;
}
void solve() {
  long long n;
  cin >> n;
  string S;
  cin >> S;
  long long cntk = 0;
  for (long long i = (0); i < (n); ++i) cntk += (S[i] == '?');
  vector<long long> A(n);
  A[0] = (S[0] == 'a');
  for (long long i = (1); i < (n); ++i) A[i] = A[i - 1] + (S[i] == 'a');
  vector<long long> C(n);
  C[n - 1] = (S[n - 1] == 'c');
  for (long long i = (n - 2); i > -1; --i) C[i] = C[i + 1] + (S[i] == 'c');
  vector<long long> KL(n);
  KL[0] = (S[0] == '?');
  for (long long i = (1); i < (n); ++i) KL[i] = KL[i - 1] + (S[i] == '?');
  vector<long long> KR(n);
  KR[n - 1] = (S[n - 1] == '?');
  for (long long i = (n - 2); i > -1; --i) KR[i] = KR[i + 1] + (S[i] == '?');
  long long ans = 0;
  for (long long i = (1); i < (n - 1); ++i) {
    if (S[i] == 'a' || S[i] == 'c') continue;
    long long cnta = A[i - 1];
    long long cntc = C[i + 1];
    long long cntkl = KL[i - 1];
    long long cntkr = KR[i + 1];
    long long isk = (S[i] == '?');
    ans = (ans + cnta * cntc * pw(3, cntk - isk)) % 1000000007;
    ans = (ans + cnta * cntkr * pw(3, cntk - 1 - isk)) % 1000000007;
    ans = (ans + cntkl * cntc * pw(3, cntk - 1 - isk)) % 1000000007;
    ans = (ans + cntkl * cntkr * pw(3, cntk - 2 - isk)) % 1000000007;
  }
  cout << ans << endl;
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();
  return 0;
}
