t = int(input())
for _ in range(t):
    n = int(input())
    arr = [int(i) for i in input().split()]
    l = 1
    s = prev = arr[0]
    for i in range(1, n):
        if prev > 0 and prev < arr[i]:
            s -= prev
            s += arr[i]
            prev = arr[i]
        elif 0 > arr[i] > prev < 0:
            s -= prev
            s += arr[i]
            prev = arr[i]
        elif arr[i] > 0 > prev or arr[i] < 0 < prev:
            s += arr[i]
            l += 1
            prev = arr[i]
    print(s)



