'''


4
5
1 2 3 -1 -2
4
-1 -2 -1 -3
10
-2 8 3 8 -4 -15 5 -2 -3 1
6
1 -1000000000 1 -1000000000 1 -1000000000



'''

n=int(input())
for i in range(0,n):
    o=int(input())
    p=input().rstrip().split(' ')
    A=0;
    S=0;
    L=[]
    Q=[]
    for i in range(0,len(p)):
        if i==0:
            if int(p[i])>0:
                L.append(int(p[i]))
            else:
                Q.append(int(p[i]))
        else:
            if int(p[i])>0:
                if len(L)!=0:
                    L.append(int(p[i]))
                else:
                    T=max(Q);
                    S+=T;
                    A+=1;
                    Q=[]
                    L.append(int(p[i]));
            else:
                if len(Q)!=0:
                    Q.append(int(p[i]))
                else:
                    T=max(L);
                    S+=T;
                    A+=1;
                    L=[]
                    Q.append(int(p[i]))
    #print(S)
    if len(L)!=0:
        S+=(max(L))
        A+=1;
    elif len(Q)!=0:
        S+=max(Q)
        A+=1;
    print(S)