t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    l = []
    p=n=0
    ps=0
    ns = -(10**9)
    if a[0]>0:
        ps = a[0]
    else:
        ns = a[0]
    for i in range(1,len(a)):
        if a[i]>0:
            if ps==0:
                l.append(ns)
                ns = -(10**9)
                ps = a[i]
            elif ps<a[i]:
                    ps = a[i]
        else:
            if ns==-(10**9):
                l.append(ps)
                ps=0
                ns= a[i]
            elif ns < a[i]:
                ns = a[i]
    if ps!=0:
        l.append(ps)
    else:
        l.append(ns )
    print(sum(l))        




