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

int main() {
	// your code goes here
	int t;
	cin>>t;
	for(int i=0;i<t;i++)
	
	{
	    long long int n,div,sum=0;
	    cin>>n;
	    if(n<2050||(n%2050)!=0)
	        cout<<"-1\n";
	   else 
	   {
	       div=n/2050;
	       if(div<10)
	        cout<<div<<"\n";
	       else
	       {
	         while(div!=0)
	         {
	             sum=sum+div%10;
	             div=div/10;
	         }
	         cout<<sum<<"\n";
	       }
	   }
	}
	
	return 0;
}
