import math
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())
for _ in range(ii()):
    n = int(input())
    a = li()
    j = 0
    i = 0
    maxx = -1000000007
    c = []
    while j < n:
        if j < n and a[j] > 0:
            i = 0
            while( j+i < n and a[j+i] > 0):
                if a[j+i] >  maxx:
                    maxx = a[j+i]
                i+=1
            j+=i
            c.append(maxx)
            maxx = -1000000007
        if j < n and a[j] < 0:
            i = 0
            while(j+i < n and a[j+i] < 0):
                if a[j+i] > maxx:
                    maxx = a[j+i]
                i+=1
            j+=i
            c.append(maxx)
            maxx = -1000000007
    print(sum(c))
