import math
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    s=a[0]
    c=0
    for i in range(1,n):
        if s//a[i]<0:
            c+=s
            s=a[i]
        else:
            if a[i]>s:
                s=a[i]
    print(s+c)