for tc in range(1, 11):
num = int(input())
buildings = list(map(int, input().split()))
views = 0
left, right = 0, 0
for idx in range(2, num-2):
# ์์ชฝ 2๊ฐ์ ๊ธฐ๋ฅ์์ ์ต๋ ๊ฐ ์ธก์
left = buildings[idx-1] if buildings[idx-1] > buildings[idx-2] else buildings[idx-2]
right = buildings[idx+1] if buildings[idx+1] > buildings[idx+2] else buildings[idx+2]
top = left if left > right else right
#์์ชฝ ๊ธฐ๋ฅ์ ์ต๋๊ฐ๋ณด๋ค ๋น๋ฉ์ด ๋ ๋์ ๊ฒฝ์ฐ, view ์ถ๊ฐ
if buildings[idx] > top :
views += buildings[idx] - top
print(f'#{tc} {views}')
min, max๋ฅผ ํ์ฉํ์ง ์๊ณ ๊ตฌํ์ ํด๋ณด๋ ค๊ณ ํ๋๋ฐ, ๊ทธ๋ฌ๋ค๋ณด๋ ์ฝ๋๊ฐ ์ด์ง ๊ธธ์ด์ง ๊ฐ์ด ์๋ ๊ฒ ๊ฐ๋ค.