1758: Min Chain

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:9 解决:3

题目描述

Raven likes games of numbers. Today he meets two numbers and thinks whether he could get a result of 1 by doing at least one operation (addition or subtraction). However, he is tired of calculation; he also wants to know the minimum steps of operation that he could get 1.

输入

The first line of the input contains an integer T, which indicates the number of test cases. In the following T rows, there are two positive integers a, b ( 0 <= a, b <= 10^9 ) in each row.

输出

For each case, output the least number of steps. If you cannot get 1, just output -1.

样例输入 复制

3
1 2
16 9
6 8

样例输出 复制

1
10
-1

提示

Sample 1: 3 - 2 = 1, One subtraction will be needed. Sample 2: 16-9+16-9+16-9-9-9+16-9-9=1,It requires 10 additions and subtractions. Sample 3: You cannot get 1.