#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long a = 0;
  long long ab = 0;
  long long abc = 0;
  long long now = 1;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'a') {
      a = (a + now) % mod;
    } else if (s[i] == 'b') {
      ab = (ab + a) % mod;
    } else if (s[i] == 'c') {
      abc = (abc + ab) % mod;
    } else {
      long long na = (3 * a + now) % mod;
      long long nab = (3 * ab + a) % mod;
      long long nabc = (3 * abc + ab) % mod;
      now = (3 * now) % mod;
      a = na;
      ab = nab;
      abc = nabc;
    }
  }
  cout << abc << endl;
  return 0;
}
