#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  long long n;
  cin >> n;
  string str;
  cin >> str;
  long long _a = 0, _ab = 0, _abc = 0, cnt = 1;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'a')
      _a = (_a + cnt) % mod;
    else if (str[i] == 'b')
      _ab = (_ab + _a) % mod;
    else if (str[i] == 'c')
      _abc = (_abc + _ab) % mod;
    else {
      _abc = (3 * _abc + _ab) % mod;
      _ab = (3 * _ab + _a) % mod;
      _a = (3 * _a + cnt) % mod;
      cnt = (3 * cnt) % mod;
    }
  }
  cout << _abc << "\n";
  return 0;
}
