#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<1000000007>;

int N;
vector<string> S;

string moji;
bool seen[55][55][30][30];
mint dp[55][55][30][30];
mint beki[50];

mint rec(int i, int j, int k, int c) {
    if (i == j) return 1;
    if (c >= moji.size()) return 0;

    // 複数行あって k が超えていたらダメと考える (狭義単調増加にできないため)
    if (k >= S[i].size()) {
        if (j - i == 1) return 1;
        else return 0;
    }
    
    // 1 行の場合
    if (j - i == 1) {
        int con = 0;
        for (int p = k+1; p < S[i].size(); ++p) if (S[i][p] == '?') ++con;
        if (S[i][k] == '?') return beki[con] * min(26, 27 - c);
        else if (S[i][k] < moji[c]) return 0;
        else return beki[con];
    }

    // メモを check
    if (seen[i][j][k][c]) return dp[i][j][k][c];

    // 場合分け
    mint res = 0;
    int mac = 0;
    for (int mid = i; mid <= j; ++mid) {
        res += rec(i, mid, k+1, 0) * rec(mid, j, k, c+1);
        if (mid == j) break;
        if (S[mid][k] != '?' && S[mid][k] != moji[c]) break;
        if (S[mid][k] == '?' && moji[c] == 'A') break;
    }
    seen[i][j][k][c] = true;
    return dp[i][j][k][c] = res;
}

int main() {
    cin >> N;
    S.resize(N);
    int ms = 0;
    for (int i = 0; i < N; ++i) cin >> S[i], ms = max(ms, (int)S[i].size());
    for (int i = 0; i < N; ++i) while (S[i].size() < ms) S[i] += 'A';
    moji = 'A';
    for (int i = 0; i < 26; ++i) moji += (char)('a' + i);
    
    memset(seen, 0, sizeof(seen));
    beki[0] = 1;
    for (int i = 0; i+1 < 50; ++i) beki[i+1] = beki[i] * 26;
    cout << rec(0, N, 0, 0) << endl;
}



Measured memory_bytes: 14516