import sys
n = int(sys.stdin.readline().strip())
for i in range(0, n):
    line = list(map(int, sys.stdin.readline().strip().split()))
    prev = line[0]
    j = 1
    t = 0
    while j < len(line) - 1:
        if line[j] - 2 * prev > 0:
            t += line[j] - 2 * prev
        prev = line[j]
        j += 1
    print(t)

7e348e8b3d7a41ee77f8584a87f3010ae8742da8
<mask token>

<mask token>
for i in range(0, n):
    line = list(map(int, sys.stdin.readline().strip().split()))
    prev = line[0]
    j = 1
    t = 0
    while j < len(line) - 1:
        if line[j] - 2 * prev > 0:
            t += line[j] - 2 * prev
        prev = line[j]
        j += 1
    print(t)

<mask token>
n = int(sys.stdin.readline().strip())
for i in range(0, n):
    line = list(map(int, sys.stdin.readline().strip().split()))
    prev = line[0]
    j = 1
    t = 0
    while j < len(line) - 1:
        if line[j] - 2 * prev > 0:
            t += line[j] - 2 * prev
        prev = line[j]
        j += 1
    print(t)

import sys
n = int(sys.stdin.readline().strip())
for i in range(0, n):
    line = list(map(int, sys.stdin.readline().strip().split()))
    prev = line[0]
    j = 1
    t = 0
    while j < len(line) - 1:
        if line[j] - 2 * prev > 0:
            t += line[j] - 2 * prev
        prev = line[j]
        j += 1
    print(t)
