最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

CF 1806A. Walking Master

2023-06-08 20:40 作者:您是打尖兒還是住店呢  | 我要投稿

YunQian is standing on an infinite plane with the Cartesian coordinate system on it. In one move, she can move to the diagonally adjacent point on the top right or the adjacent point on the left.That is, if she is standing on point (x,y)

, she can either move to point (x+1,y+1)

?or point (x?1,y)

YunQian initially stands at point (a,b)

?and wants to move to point (c,d)

. Find the minimum number of moves she needs to make or declare that it is impossible.


Input

The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of test cases follows.

The first line and only line of each test case contain four integers a, b, c, d (?108≤a,b,c,d≤108).

Output

For each test case, if it is possible to move from point (a,b) to point (c,d)

, output the minimum number of moves. Otherwise, output ?1

Example

input

6

-1 0 -1 2

0 0 4 5

-2 -1 1 1

-3 2 -3 2

2 -1 -1 -1

1 1 0 2

outputCopy

4

6

-1

0

3

3

Note

In the first test case, one possible way using 4 moves is (?1,0)→(0,1)→(?1,1)→(0,2)→(?1,2)

. It can be proven that it is impossible to move from point (?1,0) to point (?1,2) in less than 4

?moves.

就是判斷移動的次數(shù)跟能不能移動到,,主要是先判斷Y值的大小,因為只能想右上方跟左邊行走,所以判斷y值的大小變化,再根據(jù)y值大小變化去比較x值的大小,即可返回;下面是代碼:


CF 1806A. Walking Master的評論 (共 條)

分享到微博請遵守國家法律
滁州市| 辰溪县| 怀安县| 犍为县| 府谷县| 景泰县| 龙岩市| 中西区| 肇源县| 巴林右旗| 济南市| 色达县| 中方县| 紫云| 伊通| 博客| 双江| 集贤县| 浦县| 永修县| 开封县| 土默特右旗| 沾化县| 神池县| 长治县| 吴桥县| 广西| 甘洛县| 北票市| 墨江| 山阳县| 金华市| 霍林郭勒市| 光山县| 刚察县| 钦州市| 云安县| 西乌| 文昌市| 布尔津县| 新竹市|