for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    l1=[]
    l2=[]
    k=[]
    for i in range(n):
        if l[i]<0:
            if l1:
                k.append(max(l1))
            l1=[]
            l2.append(l[i])
        else:
            if l2:
              k.append(max(l2))
            l2 = []
            l1.append(l[i])
    if l1:
        k.append(max(l1))
    if l2:
        k.append(max(l2))

    print(sum(k))