#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

template<typename T> void sort(vector<T>& v) {sort(v.begin(), v.end());}

template<typename T> class Addition {
public:
  template<typename V> T operator+(const V& v) const {
    return T(static_cast<const T&>(*this)) += v;
  }
};

template<typename T> class Subtraction {
public:
  template<typename V> T operator-(const V& v) const {
    return T(static_cast<const T&>(*this)) -= v;
  }
};

template<typename T> class Multiplication {
public:
  template<typename V> T operator*(const V& v) const {
    return T(static_cast<const T&>(*this)) *= v;
  }
};

template<typename T> class Division {
public:
  template<typename V> T operator/(const V& v) const {
    return T(static_cast<const T&>(*this)) /= v;
  }
};

template<typename T> class Modulus {
public:
  template<typename V> T operator%(const V& v) const {
    return T(static_cast<const T&>(*this)) %= v;
  }
};

template<typename T> class IndivisibleArithmetic : public Addition<T>, public Subtraction<T>, public Multiplication<T> {};

template<typename T> class Arithmetic : public IndivisibleArithmetic<T>, public Division<T> {};

class Inverse {
private:
  int64_t mod;
  vector<int64_t> inv;
  
public:
  Inverse() {}
  
  Inverse(int64_t mod, int64_t n = 1000000) : mod(mod), inv(n, 1) {for (int i = 2; i < n; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;}
  
  int64_t operator()(int64_t a) const {
    if (a < int(inv.size())) return inv[a];
    int64_t b = mod, x = 1, y = 0;
    while (b) {
      int64_t t = a / b;
      swap(a -= t * b, b);
      swap(x -= t * y, y);
    }
    return x < 0 ? x + mod : x;
  }
};

int64_t inverse(int64_t n, int64_t mod) {
  Inverse inv(mod, 0);
  return inv(n);
}

class Mint : public Arithmetic<Mint> {
private:
  static int64_t mod;
  static Inverse inverse;
  int64_t val;

public:
  Mint() : val(0) {}

  Mint(const int64_t& val) {
    this->val = val % mod;
    if (this->val < 0) this->val += mod;
  }

  static void setMod(const int64_t& m) {
    mod = m;
    inverse = Inverse(m);
  }

  Mint operator-() const { return Mint(val ? mod - val : 0); }

  Mint operator+=(const Mint& m) {
    val += m.val;
    if (val >= mod) val -= mod;
    return *this;
  }

  Mint operator-=(const Mint& m) {
    val -= m.val;
    if (val < 0) val += mod;
    return *this;
  }

  Mint operator*=(const Mint& m) {
    val *= m.val;
    val %= mod;
    return *this;
  }

  Mint operator/=(const Mint& m) {
    val *= inverse(m.val);
    val %= mod;
    return *this;
  }

  Mint operator++() {return *this += 1;}

  Mint operator--() {return *this -= 1;}

  template<typename T> Mint operator-(const T& m) { return Arithmetic<Mint>::operator-(m); }

  explicit operator char() const { return val; }

  explicit operator int() const { return val; }

  explicit operator int64_t() const { return val; }

  Mint identity() const {return 1;}
};

int64_t Mint::mod = 1000000007;
Inverse Mint::inverse(1000000007);

ostream& operator<<(ostream& os, Mint a) {
  os << int64_t(a);
  return os;
}

istream& operator>>(istream& is, Mint& a) {
  int64_t n;
  is >> n;
  a = n;
  return is;
}

Mint operator+(const int& n, const Mint& m) { return m + n; }
Mint operator-(const int& n, const Mint& m) { return -m + n; }
Mint operator*(const int& n, const Mint& m) { return m * n; }
Mint operator/(const int& n, const Mint& m) { return Mint(n) / m; }

Mint operator+(const int64_t& n, const Mint& m) { return m + n; }
Mint operator-(const int64_t& n, const Mint& m) { return -m + n; }
Mint operator*(const int64_t& n, const Mint& m) { return m * n; }
Mint operator/(const int64_t& n, const Mint& m) { return Mint(n) / m; }

int main() {
  string s;
  cin >> s;
  vector<vector<Mint>> dp(s.size() + 1, vector<Mint>(4));
  dp[0][0] = 1;
  for (int i = 0; i < int(s.size()); ++i) {
    for (int j = 0; j < 4; ++j) dp[i + 1][j] = (s[i] == '?' ? 3 : 1) * dp[i][j];
    if (isalpha(s[i])) {
      dp[i + 1][s[i] - 'A' + 1] += dp[i][s[i] - 'A'];
    } else {
      for (int j = 0; j < 3; ++j) dp[i + 1][j + 1] += dp[i][j];
    }
  }
  cout << dp.back().back() << endl;
}



Measured memory_bytes: 15184