for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    l=[]
    current=a[0]
    for i in a:
        if current>0 and i>0 and i>current:
            current=i
        elif current>0 and i<0:
            l.append(current)
            current=i
        elif current<0 and i<0 and i>current:
            current=i
        elif current<0 and i>0 :
            l.append(current)
            current=i
    l.append(current)
    print(sum(l))