
In the first level, there is only one monster with power, ‘P’ = 2.
The first line of input contains an integer ‘T’, the number of test cases.
The first line of each test case contains two single space-separated integers ‘L’ and ‘M’ representing the number of levels and the modulo integer respectively.
For each test case, print a single integer modulo ‘M’ representing the number of monsters.
Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= L <= 10
3 <= M <= 50
Time Limit : 1 sec
The basic idea is to pre-compute monsters from 0 to ‘M’ levels. Monster at any level cannot be more than ‘M’ since we are using ‘M’ as modulo at each level for the number of monsters. We use a queue to traverse the monsters at each level and push the monsters of a new level into the queue.
Here is the algorithm :