for _ in range(int(input())):
    n=int(input())
    a = list(map(int, input().split(' ')))
    l=[]
    i=0
    if a[0]<0:
        t=a[0]
        while i<n:
            if a[i]<0:
                if a[i]>t:
                    t=a[i]
                i+=1
            else:
                l.append(t)
                t=a[i]
                while i<n and a[i]>0:
                    if t<a[i]:
                        t=a[i]
                    i+=1
                    if i<n and a[i]<0:
                        l.append(t)
                        t=a[i]
                    elif i==n:
                        l.append(t)
    else:
        t = a[0]
        while i < n:
            if a[i] > 0:
                if a[i] > t:
                    t = a[i]
                i += 1
            else:
                l.append(t)
                t = a[i]
                while i < n and a[i] < 0:
                    if t < a[i]:
                        t = a[i]
                    i += 1
                    if i < n and a[i] > 0:
                        l.append(t)
                        t = a[i]
                    elif i == n:
                        l.append(t)
    if len(l)==0:
        print(max(a))
    else:
        print(sum(l))