Nearest Power
Submissions: 522   Accuracy:

15.18%

  Difficulty: Easy   Marks: 2

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.
 

Input:
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 integers N and M.

 

Output:
for each case print an integer corresponding to the answer .


Constraints:
0 < M, N <= 10^9
1 <= T <= 500


Example:

Input:

1
6 3


Output:
9

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Hardik Gulati
Author: hardikgulati96


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.