#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long n;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  cin >> s;
  long long o = 1, a = 0, ab = 0, abc = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'a') a = (a + o) % 1000000007;
    if (s[i] == 'b') ab = (ab + a) % 1000000007;
    if (s[i] == 'c') abc = (abc + ab) % 1000000007;
    if (s[i] == '?') {
      abc = (3 * abc + ab) % 1000000007;
      ab = (3 * ab + a) % 1000000007;
      a = (3 * a + o) % 1000000007;
      o = (3 * o) % 1000000007;
    }
  }
  cout << abc;
  return 0;
}
