t = int(input())

def sign(a):
    return a > 0
for _ in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    if n == 1:
        print(a[0])
        continue
    curmax = a[0]
    ans = 0
    for i in range(len(a) - 1):
        curmax = max(curmax, a[i])
        if sign(a[i + 1]) != sign(a[i]):
            ans += curmax
            curmax = a[i + 1]
    curmax = max(curmax, a[n - 1])
    ans += curmax
    print(ans)