#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long c, d;
    cin >> c >> d;
    long long x = abs(c - d);
    if (x & 1)
      cout << -1 << endl;
    else {
      if (c == 0 && d == 0)
        cout << 0 << endl;
      else if (c == d)
        cout << 1 << endl;
      else
        cout << 2 << endl;
    }
  }
  return 0;
}
