MOHIB - Mohib and series

no tags 

Mohib (CoolWink), as we all known, is very brilliant in mathematics. His friend Bar has given him another problem to solve.

Bar gives him a sequence of distinct positive integers, whose average is (A+1).

If Bar append an integer x to the sequence, then the average of integers in the sequence will be A.

He asked the Mohib to tell him the largest possible integer in the sequence.

Input

First line contains T, the number of testcases (T <= 5000). 

Next T lines contain an integer x (1 <= x <= 49999) and A (x+1 <= A <= 50000).

Output

Print the largest possible integer in the sequence.

Example

Input:
1
1 2

Output:
3

hide comments
slothsphereoj: 2024-02-20 04:00:43

Such a simple yet interesting math that an average person like me can solve it as well without code copying.

mnkp: 2021-07-13 08:12:12

Too much math, I like it

sk128: 2021-04-06 15:14:36

Pen paper work :)

surajxd: 2020-07-15 15:41:34

question is easy but should have provided more test cases....

seastian: 2020-02-22 12:47:30

for largest don't check for x

prachij: 2019-12-21 10:17:22

AC in one go!!!

robosapien: 2019-12-09 19:18:49

AC in one go :P

arsundram: 2019-10-04 17:55:21

AC in one go!!

Last edit: 2019-10-04 18:20:22
kushrike: 2019-05-08 12:47:13

logical_reasoning

silentknight16: 2019-02-22 13:49:28

More of math....

Last edit: 2019-02-22 13:50:05

Added by:MoHib85
Date:2015-05-17
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ADA95 ASM32-GCC ASM32 ASM64 GAWK BASH JS-MONKEY