#include<bits/stdc++.h> 
using namespace std; 
#define int long long
#define f first
#define s second
int inf=1000000007;
void solve(); 
/*bool prime[1000001]={1};
void sieve()
{
    int i;
    for(i=0;i<1000000;i++)prime[i]=1;
    for(i=2;i*i<=1000000;i++)
    {
        if(prime[i]==1){for(int j=i*i;j<=1000000;j+=i)prime[j]=0;}
    }
 
}*/
 
bool pal(string s)
{
    int n=s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            return 0;
        }
    }
    return 1;
}
int digit(int n)
{
    int count=0;
    while(n>0)
    {
        count+=n%10;
        n/=10;
    }
    return count;
}
bool pri(int n)
{
    if(n==1)return 1;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)return 0;
    }
    return 1;
}
bool perf(int x)
{
    if(x>=0)
    {
        int sq=sqrt(x);
        return sq*sq==x;
    } 
    return 0;
}
signed main() 
{ 
   ios_base::sync_with_stdio(false);cin.tie(NULL);
   int t; 
   //sieve();
   cin>>t;
   while(t--) 
   { 
      solve(); 
      cout<<"\n"; 
   } 
   return 0;
} 
 
void solve()
{
    int n,x,i,sum=0,ans=0;
    cin>>n;
    if(n%2050!=0)
    {
        cout<<-1;
        return;
    }
    else
    {
        n/=2050;
        cout<<digit(n);
    }

}       
 