Where is the mistake in my code

Hello!

I’ve manually tried to verify my code with several custom test cases and my output was same as expected output, but still I am getting WA.

Here’s my submission
https://www.codechef.com/viewsolution/80573708

I am unable to spot the error as all the custom test cases that I ran were giving me correct output.

Consider the following test case :-

1
3 5
5 5 3
1 4 1
3 2 2

Correct Answer is 31
Solution:- Consider the FIrst and Third Question, total time taken to learn these questions is 3 + 2 = 5 and the total points earned are 5*5 + 3*2 = 31.
But your code seems to give answer as 29.