Miles to walk

0

0 votes
Problem

Rohit is stuck in the base camp of kedarkantha and he needs to get back to sankri to catch the last bus to dehradun which is M miles away and he has E units of energy.

Every hour, he can choose to do either one of the following two things:

Rest -  energy will increase by one unit

Walk -  if he walks the first hour, energy will decrease by 0, i.e., remain the same, then again if he walks in the next hour, energy will decrease by 1, then in the next hour walk by 2, and so on. Then if he rests for an hour, his energy will increase by 1, then in the next hour if he chooses to walk, his energy will decrease by 0, and so on like explained above.

Note that energy should never go below 0.

Find the minimum possible time to reach sankri. If there are multiple ways to reach in minimum time, choose the way in which maximum energy is retained.

Input

The first line of the input contains a single integer, T - the number of test cases

Each one of the next T lines contains two integers separated by a space, M E - number of miles away, and the initial energy left.

Output

For each test case, print in new line two integers, separated by a space - the minimum number of hours and the maximum energy retained while finishing the journey in minimum hours.

Constraints

1≤T≤104

1≤M≤109

0≤E≤109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first test case, after walking in the first hour, your energy remaining will be 0, so then you can't walk in the next hour and you will have to rest, thus increasing energy by 1, then walk in the third hour without losing energy.

In the second test case, after walking for the first two hours, your energy remaining will be 0, then rest in the next hour to increase the energy by 1, then walk in the next hour.

Editor Image

?