x=int(input())
for a in range(x):
    y=int(input())
    z=list(map(int,input().split()))
    s=0
    num=[]
    start=z[0]
    f=True
    for b in range(y-1):
        if abs(z[b])+abs(z[b+1])!=abs(z[b]+z[b+1]):
            num.append(start)
            s+=start
            #s=max(s,0)
            start=z[b+1]
            if b==y-2:
                f=False
        elif z[b+1]>start:
            start=z[b+1]
        #print(start)
    num.append(start)
    s+=start
    #print(num)
    print(s)
