#include <bits/stdc++.h>
using namespace std;
int n, t;
int arr[200];
string s;
const long long mod = 1000000007;
int main() {
  std::ios::sync_with_stdio(false);
  ;
  cin >> n >> s;
  long long ca = 0, cab = 0, cabc = 0;
  long long string_count = 1;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'a')
      ca = (ca + string_count) % mod;
    else if (s[i] == 'b')
      cab = (cab + ca) % mod;
    else if (s[i] == 'c')
      cabc = (cabc + cab) % mod;
    else {
      cabc = (3 * cabc + cab) % mod;
      cab = (3 * cab + ca) % mod;
      ca = (3 * ca + string_count) % mod;
      string_count = (3 * string_count) % mod;
    }
  }
  cout << cabc << '\n';
  return 0;
}
