t=int(input())
while(t>0):
    n=int(input())
    a=list(map(int,input().split()))
    k=a[0]
    l=[[k]]
    len(l)
    t-=1
    m=0
    for i in range(1,len(a)):
        if((a[i]*a[i-1])>0):
            try:
                l[m].append(a[i])
            except IndexError:
                print(m)
                print(i)
                print("s")
        else:
            try:
                l.append([a[i]])
            except IndexError:
                print(m)
                print(i)
                print("t")
            m+=1
    ans=0
    for i in l:
        ans+=max(i)
    print(ans)
