for _ in range(int(input())):
    n = int(input())
    li = list(map(int,input().split()))
    s = 0
    sli = []
    l = 1
    for i in range(1,len(li)):
        if l==1:
            s+=li[i-1]
        else:
            pass
        if li[i-1]>0 and li[i]<0:
            l+=1
            s+=li[i]
            #print(s)
        elif li[i-1]<0 and li[i]>0:
            l+=1
            s+=li[i]
            #print(s)
        else:
            if l>1:
                sli.append(s)
            l = 1
            s = 0

    if s!=0:
        sli.append(s)
    #print(sli)
    if len(sli)==0:
        print(max(li))
    else:
        print(max(sli))