for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    s=0
    i=0
    while i<n:
        if a[i]>0:
            m=0
            while i<n and a[i]>0:
                if m<a[i]:
                    m=a[i]
                i+=1
            s+=m
        else:
            m=-10**9
            while i<n and a[i]<0:
                if m<a[i]:
                    m=a[i]
                i+=1
            s+=m
    print(s)