#include <bits/stdc++.h>

using namespace std;

// ******************* SNIPPET TEMPLATE - STARTS***************
#define range(t) for (int i = 0; i < t; i++)
#define rep(i, t, q) for (int i = t; i < q; i++)
#define pb(t) push_back(t)
#define mp(a, b) make_pair(a, b)
#define rangeG(i, t) for (i = 0; i < t; i++)
#define printVec(vec)     \
    for (auto c : vec)    \
    {                     \
        cout << c << " "; \
    }                     \
    cout << "\n";
#define vec vector;

typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;

template <typename first>
void print(first f)
{
    cout << f << endl;
}

template <typename first, typename... args>
void print(first f, args... a)
{
    cout << f << " ";
    print(a...);
}

int inp(string s = "")
{
    cout << s;
    int t = 0;
    cin >> t;
    return t;
}

vector<vi> combinations(int N, int K)
{
    string bitmask(K, 1);
    bitmask.resize(N, 0);
    vvi comb;
    do
    {
        vi perm;
        for (int i = 0; i < N; ++i) // [0..N-1] integers
        {
            if (bitmask[i])
                perm.pb(i);
        }
        comb.pb(perm);
    } while (prev_permutation(bitmask.begin(), bitmask.end()));
    return comb;
}

// X--------------X---------X SNIPPET TEMPLATE - ENDS* X--------------X---------X
void solve();

void cj()
{
    int t;
    cin >> t;
    range(t)
    {
        cout << "Case #" << i + 1 << ": ";
        solve();
    }
}
void ot()
{
    int t;
    cin >> t;
    range(t)
    {
        solve();
    }
}

void solve()
{
    ll n;
    cin >> n;
    if (n % 2050 != 0)
    {
        cout << "-1\n";
        return;
    }
    ll tt = (ll)n / 2050;
    string ts = to_string(tt);
    ll ans = 0;
    for (char c : ts)
    {
        ans += c - '0';
    }
    cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ot();
    return 0;
}