        #include<bits/stdc++.h>
        using namespace std;

        #define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
        #define ll long long int
        #define max3(a,b,c) max(max((a),(b)),(c))
        #define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
        #define min3(a,b,c) min(min((a),(b)),(c))
        #define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))
        #define all(v) v.begin(),v.end()
        #define rall(v) v.rbegin(),v.rend()
        typedef pair<int,int> pii;
        typedef pair<ll,ll> pll;
        const long double PI = 3.14159265358979323846264338;
        const long long INF = 1000000000000000000;
        const long long INF1 = 1000000000;
        const long long MOD = 1000000007;
    //    int v[INF],m[INF];
 

 ll fun(ll n){
   int b=0;
   while(n>0){
       b+=n%10;
       n/=10;
   }
   return b;
 }
        int main(){
      ios
      int t;
      cin>>t;
      while(t--){
      ll n;
      cin>>n;
      if(n%2050==0){
              ll sum=n/2050;
              ll ans = fun(sum);
              cout<<ans<<endl;
      }
      else{
          cout<<-1<<endl;
      }
      
      }
}
