#include <bits/stdc++.h>

#pragma region ppd
#define ll long long
#define ld long double
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forr(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define foriter(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define endl '\n'
#define INF (ll)(1e9)
#define EPS 1e-9
#define MOD (ll)(1e9 + 7)
#define PI 3.1415926535897932384626433832795
#define set set
#define mset multiset
#define uset unordered_set
#define umset unordered_multiset
#define map map
#define mmap multimap
#define umap unordered_map
#define ummap unordered_multimap
#define FILEIO                        \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vll;
typedef vector<vll> vvll;
typedef pair<i64, i64> pll;

template <class T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template <class T> void re(T &x) { cin >> x; }
template <class Arg, class... Args> void re(Arg &first, Args &...rest) { re(first); re(rest...); }
template <class T> void re(vector<T> &a) { for0(i, a.size()) re(a[i]); }

template <class T> void pr(T &x) { cout << x << " "; }
template <class Arg, class... Args> void pr(Arg &first, Args &...rest) { pr(first); pr(rest...); }
template <class T> void pr(vector<T> &a) { for0(i, a.size()) pr(a[i]); }


#pragma endregion ppd

//=============================================================================//

void solve()
{
    ll n; cin >> n;
    if(n%2050 != 0) cout << -1;
    else {
        ll num = n/2050;
        ll ans = 0;
        while(num) {
            ans += num%10;
            num /= 10;
        }
        cout<<ans;
    }   
}

int main()
{
#ifndef ONLINE_JUDGE
    FILEIO
    auto start = chrono::high_resolution_clock::now();
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    //==================================================================================

    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
        cout << endl;
    }

//==================================================================================
#ifndef ONLINE_JUDGE
    auto finish = chrono::high_resolution_clock::now();

    chrono::duration<double> elapsed = finish - start;
    cout << "\nTime: " << elapsed.count() << " s\n";
#endif

    return 0;
}