#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  out << "[";
  for (auto k : v) out << k << " ";
  out << "]"
      << "\n";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, set<T> s) {
  out << "{";
  for (auto k : s) out << k << " ";
  out << "}"
      << "\n";
  return out;
}
template <class T, class U>
ostream& operator<<(ostream& out, pair<T, U> p) {
  out << "[ " << p.first << " , " << p.second << " ] ";
  return out;
}
template <class T, class U>
istream& operator>>(istream& in, pair<T, U>& p) {
  in >> p.first >> p.second;
  return in;
}
const long long mod = 1e9 + 7;
long long a = 0, b = 0, c = 0, ab = 0, abc = 0, pos = 1;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < int(n); i++) {
    if (s[i] == 'a') {
      a = (a + pos) % mod;
    } else if (s[i] == 'b') {
      ab = (ab + a) % mod;
    } else if (s[i] == 'c') {
      abc = (abc + ab) % mod;
    } else {
      abc = (3 * abc + ab) % mod;
      ab = (3 * ab + a) % mod;
      a = (3 * a + pos) % mod;
      pos = 3 * pos % mod;
    }
  }
  cout << abc << "\n";
  return 0;
}
