Alex, a sophomore got inspired to do mathematics after watching a movie "The Man who knew Infinity". One day, he was studying mathematics in the library and in one of the books he discovered a way to perform multiplication of numbers in a new fashion by using digits of a number. He found that method interesting and decided to formulate an algorithm for the same method. Alex finds it difficult to implement and he asks for your help.
Given a number N. Let the first digit of the number be X. P1 is the number formed using first X digits of the given number in the sequence. Let the digit after Xth digit is Y. P2 is another number formed using Y digits starting from (X + 1)th position in sequence and so on. If the number of digits to be used to form a number are more than the remaining digits, then simply form the number using digits till the last digit. Product of (P1 * P2 * P3 ... * Pi) is known as magic product. Help Alex to find the magic product.
The first line of the input contains an integer T denoting the number of test cases. Each test case contains a number N followed by values of A and B respectively.
For each test case, output the magic product modulo 10A + B.
NOTE: Any digit in the given number N will not be equal to 0.
Case 1: 54321 = (54321) % (101+3) = 7
Case 2: 35935 = ( (359) * (35) ) % (102+9) = 30
Case 3: 46542368 = ( (4654) * (23) * (68) ) % (101+5) = 1