#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    long long temp, a;
    for (int i = 0; i <n; i++) 
    {
        scanf("%lld", &temp);    
        if (temp % 2050 != 0)
        {
            printf("-1\n");
        }
        else
        {
            a = temp / 2050;
            int b = 0;
            while (a > 0)
            {
                b += a % 10;
                a /= 10;
            }
            printf("%d\n", b);
        }
    }
    return 0;
}