for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    ind=0; f=0
    if a[0]<0: ind=-1
    else: ind=1
    for i in range(1,n):
        if ind==-1 and a[i]>0: f=1; break
        elif ind==1 and a[i]<0: f=1; break
    if f==0: print(max(a))
    else:
        sign=[0]
        for i in range(1,n):
            if a[i]>0 and a[i-1]<0: sign.append(i)
            elif a[i]<0 and a[i-1]>0: sign.append(i)
        s=0
        for i in range(1,len(sign)):
            s+=max(a[sign[i-1]:sign[i]])
        s+=max(a[sign[len(sign)-1]:])
        print(s)