import math
from decimal import *
getcontext().prec = 30
t = int(input())
while t:
    t-=1
    n=int(input())
    a=list(map(int,input().split()))
    x=list()
    for i in range(n):
        if a[i]<0:
            if i:
                if a[i-1]<0:
                    a[i]=max(a[i],a[i-1])
        else:
            if i:
                if a[i-1]>0:
                    a[i]=max(a[i],a[i-1])
    for i in range(1,n):
        if a[i]*a[i-1]<0:
            x.append(a[i-1])
    if a[n-1]*a[n-2]<0:
        x.append(a[n-1])
    if len(x)==0:
        x.append(a[n-1])
    print(sum(x))




