#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  fast();
  long long n;
  string s;
  cin >> n >> s;
  long long a = 0, b = 0, c = 0;
  long long mul = 1;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'c')
      c = (c + b) % 1000000007;
    else if (s[i] == 'b')
      b = (b + a) % 1000000007;
    else if (s[i] == 'a')
      a = (a + mul) % 1000000007;
    else {
      c = (c * 3 + b) % 1000000007;
      b = (b * 3 + a) % 1000000007;
      a = (a * 3 + mul) % 1000000007;
      mul *= 3;
      mul %= 1000000007;
    }
  }
  cout << c % 1000000007 << "\n";
  return 0;
}
