The Blessing

3.4

132 votes
Ready, Mathematics, Open, Approved, Easy, Mathamatics
Problem

In a village far far away, lived a farmer named Zico. He was finding it difficult to make his two ends meet and hence, approached the god of grains, Azure. Azure granted him a blessing:

"I shall grant thou P units of food initially . After every year, thou shall come to me and the food units shall increase by a value M i.e P+M, P+M+M, ... and so on. But remember, every year the population of your village shall multiply by a factor of '2' and you must divide the food evenly among all villagers."

Zico returns back , calculates how many total units of food will he be able to secure for himself, if he becomes immortal and keeps going to Azure till the end of time and space, as we know it.

Note:
-Assume Zico is the only one in the village i.e Initial Population=1

INPUT
First line contains an integer T. T testcases follow.
Each test case contains two space-separated integers P, M

OUTPUT
For each test case, output the answer in a new line.

Constraints
1 ≤ T ≤ 105
0 ≤ P ≤ 1010
1 ≤ M ≤ 1010

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In the second test case, Zico gets 0 units in first year to be used by him, 3 units in second year to be divided amongst two ( i.e. 1.5 units for himself ) , 6 units in third to be divided amongst 4 (i.e 1.5 for himself ) and so on. . .

Editor Image

?