Given two integers N and M you have to find out an integer which is a power of M and is nearest to N.
Note: If there are multiple ways to do this, print the greatest number possible.
First line of input contains of an integer 'T' denoting number of test cases . Then T test cases follow.
Only line of each test case contains two space seperated integers N and M.
For each case print an integer corresponding to the answer .
1 <= T <= 500
0 < M, N <= 109
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.