[Solution] Find eX Solution Codechef

[Solution] Find eX Solution Codechef

Chef has 4 positive integers , and  such that  % �=� % .

Find the smallest positive integer  such that (�+�) % �=(�+�) %  holds.

It is guaranteed that such  always exists.

Input Format Find eX Solution Codechef

  • The first line of input will contain a single integer , denoting the number of test cases.
  • The first and only line of each test case contains four space-separated integers , and .

Output FormatFind eX Solution Codechef

For each test case, print a single line containing one integer — , the smallest integer satisfying the conditions.

Constraints Find eX Solution Codechef

  • 1≤�≤105
  • 1≤�,�,�,�≤109
  •  % �=� % 

Sample 1: Find eX Solution Codechef

Input

Output

3
4 7 4 8
5 1 8 2
3 2 4 3
1
2
5

Explanation: Find eX Solution Codechef

Test case 1: The smallest  satisfying the equation is 1, as (4+1) % 7=(4+1) % 8=5.

Test case 2: The smallest  satisfying the equation is 2, as (5+2) % 1=(8+2) % 2=0.

Leave a Comment