'''
for _ in range(int(input())):
    n= int(input())
    lst=[]
    for i in range(1,(n//2)+1):
        if n%i==0:
            lst.append(i)
    print(lst)
    for i1 in lst:
        if (i1+1)**(1/k)==2:
            print(n/i1)
            break
'''
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if n==1:
        print(l[0])
        break
    c=0
    k1=0
    lst=[]
    s=0
    for i in range(n-1):
        if (l[i]>0 and l[i+1]<0) or (l[i]<0 and l[i+1]>0):
            s+=max(l[k1:i+1])
            #lst.append(max(l[k1:i+1]))
            k1=i+1
    print(s+max(l[k1:]))
