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

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll              long long
#define loop(i,m,n)     for(int i=m; i<n; i++)
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define all(x)          x.begin(),x.end()
#define rall(x)         x.rbegin(),x.rend()
#define rloop(i,m,n)    for(int i=m; i>=n; i--)
#define print(x)        for(auto t : x){cout << t << " ";}cout <<"\n";
#define printl(x)      for(auto t : x)cout << t <<"\n";

#define MOD  1e9+7

typedef pair<int, int>   pii;
typedef vector<int>      vi;
typedef vector<ll>       vll;
typedef vector<double>   vd;
typedef vector<char>     vc;
typedef vector<string>   vs;
typedef set<int>         si;
typedef set<ll>          sll;
typedef set<double>      sd;
typedef set<char>        sc;
typedef set<string>      ss;
typedef map<int, int>    mii;
typedef map<ll, int>     mli;
typedef map<double, int> mdi;
typedef map<char, int>   mci;
typedef map<string, int> msi;




void solve() {
	ll n;
	cin >> n;
	if (  ceil((float)(n) / 2050) == floor((float)(n) / 2050)   ) {
		ll ans = n / 2050;
		ll res = 0;
		while (ans) {
			res += ans % 10;
			ans /= 10;

		}
		cout << res << "\n";
		return;
	}
	else {
		cout << "-1\n";
		return;
	}


	return;
}


int main() {

	fast
	ll t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}