#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tt, i, j, k, n, m, x, y, ans;
  tt = 1;
  while (tt--) {
    string s;
    cin >> n >> s;
    long long a = 0, ab = 0, abc = 0;
    long long three = 1;
    for (long long p = 0; p < n; p++) {
      if (s[p] != '?') {
        if (s[p] == 'a')
          a = (a + three) % 1000000007;
        else if (s[p] == 'b')
          ab = (ab + a) % 1000000007;
        else
          abc = (abc + ab) % 1000000007;
      } else {
        abc = (3LL * abc % 1000000007 + ab) % 1000000007;
        ab = (3LL * ab % 1000000007 + a) % 1000000007;
        a = (3LL * a % 1000000007 + three) % 1000000007;
        three = (3LL * three) % 1000000007;
      }
    }
    cout << abc;
  }
  return 0;
}
