Mike is a seventh grade student and today is his birthday. He wishes to distribute a chocolate each among his friends. He already knows all of his friends have some chocolates with them.
All his friends stand in a straight line. Mike can take all the chocolates of any one of his friend. Find the minimum number of chocolate he should have from the starting so that he can end up in giving minimum of a chocolate each to all his friends.
He will visit all his friends only once in the order 1,2, ... N.
First line of input consists of integer T denoting total number of test cases. First line of each test case contains integer N denoting number of Mike's friends. Second line of each test case contains N space separated integers ( Ai ) denoting number of chocolates the ith friend has.
Print minimum number of chocolates Mike should have from the starting for each test case in separate line.
2 3 1 2 5 2
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.