#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int test;
  cin >> test;
  while (test--) {
    long long n;
    cin >> n;

    if (n % 2050 != 0) {
      cout << "-1\n";
      continue;
    }
    long long val = n / 2050;
    long long res = 0;
    for (long long i = 1e18; i > 0; i /= 10) {
      res += val / i;
      val %= i;
    }
    cout << res << '\n';
  }
}