#include <bits/stdc++.h>

using namespace std;

int main(){
    int t,n,cd,cj;
    cin>>t;
    vector<int> br(t);
    for(int i=0;i<t;i++){
        cin>>n;
        cd=n/10;
        cj=n%10;
        if(n<10){
            br[i]=n;
        }else if((n>10 and n<100) and (cj>cd)){
            br[i]=((cd*(cd+1))/2+(cj-cd)*(cd-1))+10-cd;
        }else if((n>10 and n<100) and (cj<=cd)){
            br[i]=(cd*(cd+1))/2-(cd-cj);
        }else if(n==10){
            br[i]=10;
        }

    }
    for(int i=0;i<t;i++){
        cout<<br[i]<<endl;
        }
    return 0;
}