SP12357 SUBSHARD - Subset and upset (HARD)
Description
The whole world is crazy about subset sum. We define subset sum as sum of all subparts. A subpart is a number which is obtained by erasing certain digits and arranging the remaining numbers in the same order. You have to calculate the subset sum of the given number. Since the number can be very large return the subset sum modulo **m**.
For example if the number is 1357, then the various subparts are 1, 3, 5, 7, 13, 15, 17, 35, 37, 57, 137, 135, 157, 357, 1357 .
Input Format
First line contains **T**(1 T
Next T lines containing two numbers **n**(0 < **n** < 10 $ ^{1000} $ ) and **m**(1 < **m** < 10 $ ^{9} $ ).
Output Format
Print the subset sum modulo **m**.