#include <bits/stdc++.h>

using namespace std;

const int N=1e5+10;

int main() {
    int t;
    cin >> t;
    while (t --){
        long long n;
        cin >> n;
        if (n % 2050 == 0) {
            long long p = n / 2050;
            int s = 0;
            while (p){
                s += p % 10;
                p /= 10;
            }
            cout <<s << endl;
        }
        else puts("-1");
    }
    return 0;
}
