#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long M = 1e9 + 7;
int n;
long long pre[2][N];
long long post[2][N];
long long m3[N];
string s;
void prework() {
  for (int i = 0; i < n - 1; ++i) {
    pre[0][i + 1] = pre[0][i];
    pre[1][i + 1] = pre[1][i];
    if (s[i] == 'a') {
      pre[0][i + 1]++;
    } else if (s[i] == '?') {
      pre[1][i + 1]++;
    }
  }
  for (int i = n - 1; i > 0; --i) {
    post[0][i - 1] = post[0][i];
    post[1][i - 1] = post[1][i];
    if (s[i] == 'c') {
      post[0][i - 1]++;
    } else if (s[i] == '?') {
      post[1][i - 1]++;
    }
  }
  m3[0] = 1;
  for (int i = 1; i < N; ++i) {
    m3[i] = (m3[i - 1] * 3 % M);
  }
}
int main() {
  cin >> n;
  cin >> s;
  prework();
  long long ans = 0;
  for (int i = 1; i < n - 1; ++i) {
    if (s[i] == 'b' || s[i] == '?') {
      ans = (ans +
             (pre[0][i] * post[0][i] % M * m3[pre[1][i] + post[1][i]] % M)) %
            M;
      if (pre[1][i] > 0)
        ans = (ans + (post[0][i] * pre[1][i] % M *
                      m3[pre[1][i] - 1 + post[1][i]] % M)) %
              M;
      if (post[1][i] > 0)
        ans = (ans + (pre[0][i] * post[1][i] % M *
                      m3[pre[1][i] - 1 + post[1][i]] % M)) %
              M;
      if (pre[1][i] > 0 && post[1][i] > 0) {
        ans = (ans + (pre[1][i] * post[1][i] % M *
                      m3[pre[1][i] - 2 + post[1][i]] % M)) %
              M;
      }
    }
  }
  cout << ans;
}
