Joker is back again with his destructive plan . He has set N bombs in various parts of Gotham city and has challenged the police department to defuse all bombs in one day . City can be treated as a 1-D line with 'N' bombs situated in such a manner that distance of 1st bomb is 'x' , 2nd bomb is ' x2 ' , 3rd bomb is ' x3 ' ....... nth bomb is ' xn ' , where ' x ' is measured from the start (left end ) . Since the number of bombs planted is very large , Gordon and his team find it impossible to diffuse all the bombs in one day and once again Gordon asks for Batman's help . He keeps his bomb diffusing squad ready at the start and requests batman to bring all the bombs back to the start . Since the bombs are very heavy , batman can carry only one bomb at a time . For each bomb , he first travels upto the bomb location and then carry it back upto the start and thus covering the same distance ( bomb's distance from the start ) twice . For example for N=4 , total distance covered by batman is
x + x + x2 + x2 + x3 + x3 + x4 + x4 where x is the distance of the first bomb in kms.
Now Batman is wondering how much distance he has to cover in order to bring all bombs back to the start but he is little weak in calculations involving large numbers and asks for your help to calculate the total distance he has to cover . Since the total distance can be very large , he wants you to calculate the total distance mod M , i.e he wants total_distance % M.
First line of input contains integer t , number of test cases. Each t lines contains contains 3 integers N - number of bombs planted in the city , x - distance of first bomb and M - modulo .
Each line of output contains a single integer , the required answer.
1<=T<=50
1<=N,x<=109
1< M<=100000 (105)
For the 4th test case , i.e 2 8 100 , batman has to travel distance = 8 + 8 + 64 + 64 = 144 mod 100 = 44