#include <bits/stdc++.h>
long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return ((x / gcd(x, y)) * y); }
using namespace std;
void fast();
int main() {
  fast();
  int t;
  cin >> t;
  while (t--) {
    int c, d;
    cin >> c >> d;
    if (c == 0 && d == 0) {
      cout << 0 << "\n";
    } else if (c == d) {
      cout << 1 << "\n";
    } else {
      int dif = abs(c - d);
      if (dif % 2 == 0) {
        cout << 2 << "\n";
      } else
        cout << -1 << "\n";
    }
  }
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
