MOHIB - Mohib and series

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

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

hide comments
2015-06-11 11:16:29 Gaurav kumar
AC in one go:D
easy one!!!
2015-06-07 21:04:07 priyank
all number are distinct excluding x :)
2015-06-02 22:41:19 Arnab Mitra
AC in 1 go :D use int for avg also.
2015-05-29 04:32:23 Mani Soni
costed me 2 wa but feeling good to solve the question..
2015-05-26 11:58:33 :.Mohib.:
All the number in sequence are distinct excluding x... @abishek
2015-05-26 06:12:06 ABHISHEK
does the sequence still contains all distinct number after including x...
2015-05-25 07:52:40 Bhuvnesh Jain
Pay attention to the word "distinct" costed me 1 WA.
2015-05-23 19:23:27 Diksha Jaiswal
AC in 1 go :)
2015-05-22 22:54:02 CounterNormalize
Any tricky test cases????
2015-05-22 19:52:50 Abhinav
Yaaaeeeee AC in 1 go :D
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.