#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long tota = 0, totb = 0, totc = 0, add = 1;
  long long mod = 1e9 + 7;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'a') {
      tota += add;
    } else if (s[i] == 'b') {
      totb += tota;
    } else if (s[i] == 'c') {
      totc += totb;
    } else {
      totc *= 3;
      totc += totb;
      totb *= 3;
      totb += tota;
      tota *= 3;
      tota += add;
      add *= 3;
    }
    tota %= mod, totb %= mod, totc %= mod, add %= mod;
  }
  cout << totc << "\n";
  return 0;
}
