
for ad in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if l[0]>0:
        t=1
    else:
        t=-1
    x=[0];c=0
    for i in range(1,n):
        if t==1:

            if i==n-1:
                if l[i]>0:
                    c+=max(l[x[0]:n])
                else:
                    c+=l[i]
                    c+=max(l[x[0]:i])
            elif l[i]<0:
                x.append(i)
                c+=max(l[x[0]:x[1]])

                t=-1;x=[i]

        elif t==-1:

            if i==n-1:
                if l[i] < 0:
                    c += max(l[x[0]:n])
                else:
                    c += l[i]
                    c += max(l[x[0]:i])
            elif l[i] > 0:
                x.append(i)
                c += max(l[x[0]:x[1]])
                t = 1

                x = [i]
    if n==1:
       c=l[0]
    print(c)



