#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
using PII=pair<ll,ll>;
using PIII=pair<int,pair<int,int>>;
const ld ESP = 1e-10;
const ld PI = acosl(-1);
const int N=1e5+10;
const int M=2e5+10;
// const int mod = 1000000007;
const int mod = 998244353;
//随机化
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dis(1, 1000000000);
// cout<<fixed<<setprecision(10);


void solve(){
    string s;
    cin>>s;
    int c[4]={26,26,10,4};
    int f[4]={};
    for(int i=0;i<s.size();i++){
        if(s[i]<='Z'&&s[i]>='A'){
            f[0]++;
        }else if(s[i]<='z'&&s[i]>='a'){
            f[1]++;
        }else if(s[i]<='9'&&s[i]>='0'){
            f[2]++;
        }else{
            f[3]++;
        }
    }
    int ans=0;
    for(int i=0;i<4;i++){
        if(f[i]==1){
            ans+=(c[i]-1);
        }else{
            ans+=f[i]*65;
        }
    }cout<<ans<<'\n';
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _=1;
    cin>>_;
    while(_--){
        solve();
    }
    return 0;
}