#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long ans = 0;
  long long ca = 0, cab = 0, cabc = 0, slen = 1;
  for (char c : s) {
    if (c == 'a')
      ca = (slen + ca) % mod;
    else if (c == 'b')
      cab = (ca + cab) % mod;
    else if (c == 'c')
      cabc = (cabc + cab) % mod;
    else {
      cabc = (3 * cabc + cab) % mod;
      cab = (ca + 3 * cab) % mod;
      ca = (slen + 3 * ca) % mod;
      slen = (3 * slen) % mod;
    }
  }
  cout << cabc << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
