Medium Math > Number Theory
Sifat loves digits, yes you heard that right. But his thinking is really complex and some times he represents his questions also with so much complexity. Recently he found an amazing thing. See if an integer's last digit is divisible by 2, then the whole integer is divisible by 2. Again if sum of all the digits of an integer is divisible by 3, then the whole integer is divisible by 3. With this he came up with a great problem. Sifat will give you a very large integer, you have to tell him whether it is divisible by 8 or not. But here is a catch. Sifat won't give you the whole number. He will hide a digit and will replace that with ' A ' . Now when N will be divisible by 8, you have to tell him the value of ' A '. If there is multiple solution for ' A ' , tell the lowest number.The number can't have any leading zeroes. If there is no way the number can be divisible by 8, tell him " NO ". Remember you are a busy person, so you don't want to waste more than 0.5 seconds to answer per question asked by Sifat. Input: ------ Input starts with an integer **T (1 <= 20)**, denoting the number of test cases. Each case contains an string of length **N (8 ≤ N ≤ 10^7)**. The string should have no leading zeroes. **' A ' will be between 1 to ( n - 4 ) index.** Output: ------- For each line of output print "YES" if N is divisible by 8 else "NO" , without the ( " " ) sign. If N is divisible by 8, then print the value of ' A ' . **' A ' will appear only once in the string.** Sample Input ------------ 2 123A4128 91A45123 Sample Output ------------- YES 0 NO Hints ------------- For the first sample, A can be any value from 0 to 9 , so we print 0 as it is the lowest. The second sample can never be divisible by 8 for any value of A ( 0 - 9 ) .