


for k in range(int(input())):

    a = int(input())


    t = list(map(int,input().split()))




    start=t[0]

    u=0
    for j in range(a):
        if t[j]<0:
            if start<0:
                if t[j]>start:
                    start=t[j]
            elif start>0:
                u+=start
                start = t[j]
        elif t[j]>0:
            if start>0:
                if t[j]>start:
                    start = t[j]
                else:
                    pass
            elif start<0:
                u+=start
                start = t[j]

    u+=start


    print(u)
            
