이득을 구하기 위해서 최대 값을 찾고 갱신하는 과정의 풀이를 하려 했으나 실패
리스트를 뒤에서부터 탐색, 가장 뒤에 있는 값을 최대 값으로 설정
이득을 계산하고 새로운 최대 값을 만나면 갱신
t = int(input())
answer = []
for i in range(t):
n = int(input())
price = list(map(int, input().split()))
best_price = price[-1]
result = 0
for j in range(2, n+1):
if best_price > price[-j]:
result += (best_price - price[-j])
elif best_price < price[-j]:
best_price = price[-j]
answer.append(result)
for i in range(t):
print("#%d %d" %(i+1, answer[i]))