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