#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define int           int64_t //store upto 10^18

///////////////////////////////////////////////////////////////////////
int digitssum(int n, int val)
{
    if (n < 10)
    {
        val = val + n;
        return val;
    }
    return digitssum(n / 10, (n % 10) + val);
}
void solve() { 
 int n=0;
 cin>>n;
 int x=(n/2050);
 if(n<2050 || (n%2050)!=0)
 {
     cout<<-1<<endl;
     return ;
 }
 
     cout<<digitssum(x,0)<<endl;
     return ;
 
 
 



}
 //////////// MAIN CODE ENDS HERE ////
signed main() {
 

 
    int test = 1;
   cin >> test;
 
   
     
    for(int i = 1; i <= test; ++i){
        solve();
    }
 
    return 0;
}