description: <image>
  
  William has two numbers a and b initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer k is picked, which is then used to perform one of the following operations: (note, that for each operation you can choose a new positive integer k)
  
    1. add number k to both a and b, or 
    2. add number k to a and subtract k from b, or 
    3. add number k to b and subtract k from a. 
  
  
  
  Note that after performing operations, numbers a and b may become negative as well.
  
  William wants to find out the minimal number of operations he would have to perform to make a equal to his favorite number c and b equal to his second favorite number d.
  
  Input
  
  Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). Description of the test cases follows.
  
  The only line of each test case contains two integers c and d (0 ≤ c, d ≤ 10^9), which are William's favorite numbers and which he wants a and b to be transformed into.
  
  Output
  
  For each test case output a single number, which is the minimal number of operations which William would have to perform to make a equal to c and b equal to d, or -1 if it is impossible to achieve this using the described operations.
  
  Example
  
  Input
  
  
  6
  1 2
  3 5
  5 3
  6 6
  8 0
  0 0
  
  
  Output
  
  
  -1
  2
  2
  1
  2
  0
  
  Note
  
  Let us demonstrate one of the suboptimal ways of getting a pair (3, 5):
  
    * Using an operation of the first type with k=1, the current pair would be equal to (1, 1). 
    * Using an operation of the third type with k=8, the current pair would be equal to (-7, 9). 
    * Using an operation of the second type with k=7, the current pair would be equal to (0, 2). 
    * Using an operation of the first type with k=3, the current pair would be equal to (3, 5). 
solution: /*===============================
  Author   :   Shadman Shariar   ||
  ===============================*/
  import java.io.*;
  import java.util.*;
  ///import java.math.BigInteger;
  //import java.text.DecimalFormat;
  public class Main {
  public static Main obj = new Main();
  public static int [] dx = {-1, 1, 0, 0, -1, -1, 1, 1};
  public static int [] dy = {0, 0, -1, 1, -1, 1, -1, 1};
  //public static FastReader fr = new FastReader();
  //public static Scanner input = new Scanner(System.in);
  //public static PrintWriter pw = new PrintWriter(System.out);
  //public static DecimalFormat df = new DecimalFormat(".000");
  //public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  public static void main (String[] args) throws Exception {
  Scanner input = new Scanner(System.in);
  //BigInteger bi = new BigInteger("000");
  //StringBuilder sb = new StringBuilder();
  //StringBuffer sbf = new StringBuffer();
  //StringTokenizer st = new StringTokenizer("string","split");
  //Vector vc = new Vector();
  //ArrayList<Integer> al= new ArrayList<Integer>();
  //LinkedList<Integer> ll= new LinkedList<Integer>();
  //Stack <Integer> stk = new Stack <Integer>();
  //Queue <Integer> q = new LinkedList<Integer>();
  //ArrayDeque<Integer> ad = new ArrayDeque<Integer>();
  //PriorityQueue <Integer> pq = new PriorityQueue<Integer>();
  //PriorityQueue <Integer> pqr = new PriorityQueue<Integer>(Comparator.reverseOrder());
  //HashSet<Integer> hs = new HashSet<Integer>();
  //LinkedHashSet<Integer> lhs = new LinkedHashSet<Integer>();
  //TreeSet<Integer> ts = new TreeSet<Integer>();
  //TreeSet<Integer> tsr = new TreeSet<Integer>(Comparator.reverseOrder());
  //HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
  //LinkedHashMap<Integer,Integer> lhm = new LinkedHashMap<Integer,Integer>();
  //TreeMap<Integer,Integer> tm = new TreeMap<Integer,Integer>();
  //TreeMap<Integer,Integer> tmr = new TreeMap<Integer,Integer>(Comparator.reverseOrder());
  //LinkedList<Integer> adj[] = new LinkedList[size];
  //=================CODE STARTS FROM HERE==================//
  
  int t = input.nextInt();
  
  for (int i = 0; i < t; i++) {
  	
  	long c = input.nextLong();
  	long d = input.nextLong();
  	long dis = Math.abs(c-d);
      if (Math.abs(c-d)==1) {
  		
  		System.out.println(-1);
  		continue;
  	}
  	if (dis%2!=0) {
  		
  		System.out.println(-1);
  		continue;
  		
  	}
  	if (c==0&&d==0) {
  		
  		System.out.println(0);
  	
  	    continue;
  	}
  	
  	if(c==0||d==0) {
  		
  		System.out.println(2);
  		continue;
  		
  	}
  	
  	if (c==d) {
  		System.out.println(1);
  		continue;
  	}
  	
  	if (Math.abs(c-d)>1) {
  		System.out.println(2);
  		continue;
  	}
  	
  }
  
  
  
  
  //=====================CODE ENDS HERE=====================//
          //pw.close();
          input.close();
  		System.exit(0);
  }
  //===========================================================================================//
  public static long lcm(long a,long b){return (a/gcd(a,b))*b;}
  public static long gcd(long a,long b){if(a==0)return b;return gcd(b%a,a);}
  public static long nPr(long n,long r){return factorial(n)/factorial(n-r);}
  public static long nCr(long n,long r){return factorial(n)/(factorial(r)*factorial(n-r));}
  public static long factorial(long n){return (n==1||n==0)?1:n*factorial(n-1);}
  public static long countsubstr(String str){long n=str.length();return n*(n+1)/2;}
  public static boolean perfectsquare(long x){if(x>=0)
  {long sr=(long)(Math.sqrt(x));return((sr*sr)==x);}return false;}
  public static boolean perfectcube(long N){int cube;int c=0;for(int i=0;i<=N;i++){cube=i*i*i;
  if(cube==N){c=1;break;}else if (cube>N){c=0;break;}}if(c==1)return true;else return false;}
  public static boolean[] sieveOfEratosthenes(int n){boolean prime[]=new boolean[n+1];
  for (int i = 0; i <= n; i++)prime[i] = true;for (int p = 2; p * p <= n; p++){
  if(prime[p]==true){for(int i=p*p;i<=n;i+=p)prime[i]=false;}}prime[1]=false;return prime;}
  public static int binarysearch(int arr[],int l,int r,int x) 
  {if (r >= l){int mid = l + (r - l) / 2;if (arr[mid]==x)return mid;if(arr[mid]>x)return
  binarysearch(arr, l, mid - 1, x);return binarysearch(arr, mid + 1, r, x);}return -1;}
  public static void rangeofprime(int a,int b){int i, j, flag;for (i = a; i <= b; i++)
  {if (i == 1 || i == 0)continue;flag = 1;for (j = 2; j <= i / 2; ++j) {if (i % j == 0)
  {flag = 0;break;}}if (flag == 1)System.out.println(i);}}
  public static boolean isprime(long n){if(n<=1)return false;else if(n==2)return true;else if
  (n%2==0)return false;for(long i=3;i<=Math.sqrt(n);i+=2){if(n%i==0)return false;}return true;}
  //===========================================================================================//
  public static class FastReader {
  		BufferedReader br;
  		StringTokenizer st;
  		public FastReader() {
  			br = new BufferedReader(new InputStreamReader(System.in));
  		}
  		String next() {
  			while (st == null || !st.hasMoreElements()) {
  				try {
  					st = new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  			}
  			return st.nextToken();
  		}
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  		double nextDouble() {
  			return Double.parseDouble(next());
  		}
  		String nextLine() {
  			String str = "";
  			try {
  				str = br.readLine();
  			} catch (IOException e) {
  				e.printStackTrace();
  			}
  			return str;
  		}
  	}
  }