for _ in range(int(input())):
    n=int(input())
    a=[int(i) for i in input().split()]
    a.append(0)
    summ=0
    c=[]
    for i in range(n):
        c.append(a[i])
        if (a[i+1]>0 and a[i]>0) or (a[i+1]<0 and a[i]<0):
            c.append(a[i+1])
        else:
            summ+=max(c)
            c=[]
    print(summ)
