SP15996 SNGNM2 - Number Magic II

Description

num (> 9) be a positive integer. sum is defined as sum\_of\_digits\_of\_num. avg is defined as sum / digits\_in\_num and avg takes only integer values (for example 34 / 5 is equal to 6, i.e. integer part of 6.8). Now digits of num are rearranged by taking avg as pivoting element. Rearrangement is done according the following method - **\[step 1\]** **new\_num = avg; read digits of num if (digit > avg) place digit at rightmost place in new\_num** else **place digit at leftmost place in new\_num** **\[step 2\]** new\_num is again rearranged into two numbers, eve\_number (**formed by taking digits of new\_num at places 2, 4, 6, ...**) and odd\_number (**formed by taking digits of new\_num at places 1, 3, 5, ...**). Remember that counting of digit place starts from leftmost digits as 1, 2, 3, 4... \[step 3\] **if (eve\_number has < 3 digits) store the number else calculate avg and again start from process 1** **if (odd\_number has < 3 digits) store the number else calculate avg and again start from step 1** Finally all desired numbers are stored and now we have to find two magical coefficients of num, named as alpha and beta. \[method digit\_sum\] **number = num** **do { number = sum of digits of number** } while (number >= 10) **dig\_**sum $ _{ } $ = number \[alpha\] **digit\_sum(summation\_of\_stored\_numbers)** **\[beta\] **digit\_sum(summation\_of\_digit\_sum(stored\_numbers))**** we will say num is magic number if alpha, beta and |aplha - beta| are digits of num.

Input Format

First line of input is t (< 101), total number of test cases. Each test case has n (< 501) as its first input and next n lines contains num (< 10 $ ^{101} $ ).

Output Format

For each test case, write exactly n lines containing value of alpha and beta; and yes or no according to whether or not num is magic number.