import math

for _ in range(int(input())):
    n=int(input())
    lis=list(map(int,input().split()))
    l=[]
    if lis[0]<0:
        f=0
    else:
        f=1
    x=[]
    for i in range(n):
        if f==0 and lis[i]<0:
            x.append(lis[i])
        elif f==1 and lis[i]>0:
            x.append(lis[i])
        elif f==0 and lis[i]>0:
            l.append(x)
            x=[lis[i]]
            f=1
        else:
            l.append(x)
            x=[lis[i]]
            f=0
    l.append(x)
    s=0
    for i in range(len(l)):
        s+=max(l[i])
    print(s)

