t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int, input().split()))
    dl, su, masu, madl=1, 0, 0, 0
    nn=a[0]
    for i in range(1, n):
        if (a[i]>0 and a[i-1]>0) or (a[i]<0 and a[i-1]<0):
            if nn<0 and a[i]<0: nn=max(a[i], a[i-1], nn)
            elif nn>0 and a[i]>0: nn=max(a[i], a[i-1], nn)
            else: nn=max(a[i], a[i-1])
        elif (a[i]>0 and a[i-1]<0) or (a[i]<0 and a[i-1]>0): dl+=1; su+=nn; nn=a[i]
        elif madl<dl: madl=dl; masu=su; dl=1; su=a[i]
        elif dl==madl and su>masu: masu=su; dl=1; su=a[i]
    #for i in range(1, n):
        #if (a[i]>0 and a[i-1]<0) or (a[i]<0 and a[i-1]>0): dl+=1; su+=a[i]
        #elif madl<dl: madl=dl; masu=su; dl=1; su=a[i]
        #elif dl==madl and su>masu: masu=su; dl=1; su=a[i]
        #print(dl, su, masu, madl, i)
    su+=nn
    if madl<dl: madl=dl; masu=su
    elif dl==madl and su>masu: masu=su 
    print(masu)