#include <bits/stdc++.h>
using namespace std;
int main() {
  long long mod = 1e9 + 7;
  long long a = 0, ab = 0, abc = 0, t = 1;
  long long n;
  string s;
  cin >> n >> s;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'a') {
      a = (a + t) % mod;
    } else if (s[i] == 'b') {
      ab = (ab + a) % mod;
    } else if (s[i] == 'c') {
      abc = (abc + ab) % mod;
    } else {
      abc = (abc * 3 + ab) % mod;
      ab = (ab * 3 + a) % mod;
      a = (a * 3 + t) % mod;
      t = t * 3 % mod;
    }
  }
  cout << abc << endl;
}
