#include <bits/stdc++.h>
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 3e5 + 5;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll c_a = 0, c_ab = 0, c_abc = 0, c = 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'a')
      c_a = (c_a + c) % mod;
    else if (s[i] == 'b')
      c_ab = (c_ab + c_a) % mod;
    else if (s[i] == 'c')
      c_abc = (c_abc + c_ab) % mod;
    else {
      c_abc = (3 * c_abc + c_ab) % mod;
      c_ab = (3 * c_ab + c_a) % mod;
      c_a = (3 * c_a + c) % mod;
      c = (3 * c) % mod;
    }
  }
  cout << c_abc;
  return 0;
}
