PivotOJ

Transforming Pairs

시간 제한: 2000ms메모리 제한: 2048MB출처: USACO 2025 February PlatinumBOJ 33739

문제

Answer QQ (1Q1051\le Q\le 10^5) independent queries each of the following form:

You are given four integers a,b,c,da,b,c,d (1018a,b,c,d1018-10^{18}\le a,b,c,d\le 10^{18}). In one operation you can either do a+=ba\mathrel{+}=b, or b+=ab\mathrel{+}=a. Determine the minimum number of operations to transform (a,b)(a,b) into (c,d)(c,d), or if it is impossible to do so, output 1-1.

입력

The first line contains QQ.

The next QQ lines each contain four integers a,b,c,da,b,c,d.

출력

The answer for each query on a separate line.

예제

예제 1

입력
4
5 -3 -1 -3
5 3 5 2
5 3 8 19
5 3 5 3
출력
2
-1
3
0
코드를 제출하려면 로그인하세요.