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