// May this submission at accepted!

#pragma GCC optimize ("O3")
#pragma GCC tarat ("tune=native")
#pragma GCC tarat ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール

// 行列演算
// pdivの余りを取りたくない場合はoperator+=/-=/*のコメントアウトを適宜
constexpr ll pdiv = 1000000007LL;

template <typename T = ll>
class matrix {
private:
    size_t col_size, row_size;
    vector<T> raw;
public:
    matrix() : col_size(0), row_size(0), raw() {}
    matrix(size_t n) : col_size(1), row_size(n), raw(n, 0) {}
    matrix(size_t n, size_t m) : col_size(m), row_size(n), raw(n * m, 0) {}
    matrix(const vector<vector<T>> &a) : col_size(a.size() ? a[0].size() : 0), row_size(a.size()), raw(col_size * row_size) {
        for (size_t i = 0; i < row_size; i++) {
            for (size_t j = 0; j < col_size; j++) {
                at(i, j) = a[i][j];
            }
        }
    }
    matrix(initializer_list<T> init) : col_size(init.size()), row_size(1), raw(init) {}
    matrix(initializer_list<initializer_list<T>> init) : col_size(0), row_size(0), raw() {
        const size_t n = init.size();
        const size_t m = [&]() {
            size_t maxm = 0;
            for (const auto& initi : init) {
                const size_t mi = initi.size();
                if (mi > maxm) maxm = mi;
            }
            return maxm;
        }();
        tie(row_size, col_size) = make_pair(n, m);
        raw.resize(n * m);
        size_t i = 0, j = 0;
        for (const auto &initi : init) {
            for (const auto &v : initi) {
                at(i, j++) = v;
            }
            i++; j = 0;
        }
    }
    size_t rows() const { return row_size; }
    size_t cols() const { return col_size; }
    const T& at(const size_t i, const size_t j) const { return raw.at(i * col_size + j); }
    const T& at(const size_t i) const { return raw.at(i); }
    T& at(const size_t i, const size_t j) { return raw.at(i * col_size + j); }
    T& at(const size_t i) { return raw.at(i); }
    T& operator() (size_t i, size_t j) { return raw[i * col_size + j]; }
    T& operator() (size_t i) { return raw[i]; }
    T& operator[] (size_t i) { return raw[i]; }
    const T& operator() (size_t i, size_t j) const { return raw[i * col_size + j]; }
    const T& operator() (size_t i) const { return raw[i]; }
    const T& operator[] (size_t i) const { return raw[i]; }
    matrix<T>& operator+= (const matrix<T> &a) {
        for (size_t i = 0; i < row_size; i++) {
            for (size_t j = 0; j < col_size; j++) {
                // at(i, j) += a.at(i, j);
                if ((at(i, j) += a.at(i, j)) >= pdiv) at(i, j) -= pdiv;
            }
        }
        return *this;
    }
    matrix<T>& operator-= (const matrix<T> &a) {
        for (size_t i = 0; i < row_size; i++) {
            for (size_t j = 0; j < col_size; j++) {
                // at(i, j) -= a.at(i, j);
                if ((at(i, j) +=  pdiv - a.at(i, j)) >= pdiv) at(i, j) -= pdiv;
            }
        }
        return *this;
    }
    matrix<T> operator* (const matrix<T> &a) {
        assert(col_size == a.row_size);
        const size_t n = row_size, m = col_size, q = a.col_size;
        matrix<T> r(n, q);
        for (size_t i = 0; i < n; i++) {
            for (size_t k = 0; k < m; k++) {
                for (size_t j = 0; j < q; j++) {
                    // r.at(i, j) += at(i, k) * a.at(k, j);
                    (r.at(i, j) += at(i, k) * a.at(k, j) % pdiv) %= pdiv;
                }
            }
        }
        return r;
    }
    
    matrix<T> operator+ (const matrix<T> &a) {
        matrix<T> r = *this;
        return r += a;
    }
    matrix<T> operator- (const matrix<T> &a) {
        matrix<T> r = *this;
        return r -= a;
    }
    matrix<T>& operator*= (const matrix<T> &a) {
        return *this = move(*this * a);
    }
    operator T () const {
        assert(col_size == 1 && row_size == 1);
        return raw[0];
    }
    static matrix<T> eye(size_t n) {
        matrix<T> r(n, n);
        for (size_t i = 0; i < n; i++)
            r.at(i, i) = 1;
        return r;
    }
    matrix<T> transpose() {
        matrix<T> r(col_size, row_size);
        for (size_t i = 0; i < col_size; i++) {
            for (size_t j = 0; j < row_size; j++) {
                r.at(i, j) = at(j, i);
            }
        }
        return r;
    }
    matrix<T> pow(long long int n) {
        assert(row_size == col_size);
        matrix<T> r = eye(row_size);
        matrix<T> a = *this;
        while (n) {
            if (n & 1) r *= a;
            n /= 2;
            if (n) a *= a;
        }
        return r;
    }
};
template <typename T>
void DUMPMTR(matrix<T> m) {
    cerr << "[DEBUG] DUMPMTR: " << endl;
    for (size_t i = 0; i < m.rows(); i++) {
        cerr << " ["[!i] << "[";
        for (size_t j = 0; j < m.cols(); j++) {
            cerr << setw(4) << m(i, j) << " ]"[j+1 == m.cols()];
        }
        if (i+1 == m.rows()) cerr << ']';
        cerr << endl;
    }
}


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    map<char, matrix<ll>> lmap;
    lmap['A'] = {
        {1, 0, 0, 0},
        {0, 1, 0, 0},
        {0, 0, 1, 0},
        {1, 0, 0, 1}
    };
    lmap['B'] = {
        {1, 1, 0, 0},
        {0, 1, 0, 0},
        {0, 0, 1, 0},
        {0, 0, 0, 1}
    };
    lmap['C'] = {
        {1, 0, 0, 0},
        {0, 1, 1, 0},
        {0, 0, 1, 0},
        {0, 0, 0, 1}
    };
    lmap['?'] = lmap['A'] + lmap['B'] + lmap['C'];

    matrix<ll> x = {0, 0, 0, 1};
    matrix<ll> y = matrix<ll>({0, 0, 1, 0}).transpose();
    matrix<ll> a = matrix<ll>::eye(4);
    string s; cin >> s;
    for (char &c : s) {
        a *= lmap[c];
    }
    cout << x * a * y << endl;
    
}

Measured memory_bytes: 512