#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    if (a == b) {
      if (a == 0)
        cout << 0 << "\n";
      else
        cout << 1 << "\n";
    } else if ((a + b) % 2)
      cout << -1 << "\n";
    else
      cout << 2 << "\n";
  }
}
