Given a simple weighting scale with two pans, we are given a weight T and some other weights which are the powers of a specific number a, our goal is to balance these pans using the given weights. More formally we need to satisfy this equation,
T + (some power of a) = (some other powers of a)
Remember that we are given exactly one weight corresponding to one power.
Examples: Input : T = 11 and a = 4 Then scale can be balanced as, 11 + 4 + 1 = 16 Output : YES, pans can be balanced
The first line of input contains an integer Test denoting the Test cases. Then Test test cases follow.
Second line contains value of T and a.
Yes, if pans can be balanced; else NO
1 ≤ Test ≤ 50
1 ≤ a ≤ T ≤ 1000