        // violet apricity
        // Do all I can do.Do good to be good.

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>
#include<sstream>
#include<numeric>
#include<queue>

#define STD using namespace std;
#define ll long long
#define db double
#define ldb long double
#define IOS std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0);
#define MAX 88888888
#define INF 0x3f
#define r0 return 0;
#define SYP system("pause");
#define endl '\n'

STD
int main()
{
    IOS
    int t;cin>>t;
    while(t--){
        ll n;cin>>n;
        if(n%2050!=0){cout<<-1<<'\n';continue;}
        ll d=n/2050;
        ll ans=0;
        while(d){
            ans+=(d%10);
            d/=10;
        }
        cout<<ans<<'\n';
    }
    //SYP
    r0
}