#include<bits/stdc++.h>
using namespace std;
#define for0(i,n) for(long long i = 0;i < n;i++)
#define for1(i,n) for(long long i = 1;i <= n;i++)
#define forr(i,a,n) for(long long i = a;i <= n;i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
int sumDigits(long long no)
    {
        return no == 0 ? 0 : no % 10 + sumDigits(no / 10);
    }

int main()
{
    unsigned long long t,n;
    cin >> t;
    while(t--)
    {
        cin >> n;
        if(n%2050 == 0 && n != 0)
        {
            cout << sumDigits(n/2050)<<endl;
        }
        else
        {
            cout << -1 << endl;
        }
    }


}