import math

t = int(input())
for q in range(0, t):
    n = int(input())
    a = list(map(int, input().split()))
    b = []
    for i in range(0, n):
        b.append(a[i] > 0)
    ans = 0
    ma = a[0]
    for i in range(1, n):
        if b[i] != b[i - 1]:
            ans += ma
            ma = a[i]
        else:
            ma = max(ma, a[i])
    ans += ma
    print(ans)
