def ans(a):
    count = 0
    s = ''
    temp_l = [[a[0]]]
    arr = []
    for i in range(1,len(a)):
        if (a[i]>0 and a[i-1]<0) or (a[i]<0 and a[i-1]>0):
            temp_l[-1].append(a[i])

        else:
            temp_l.append([a[i]])
    print(temp_l)
    q = -1
    w = [min(a)] #ans
    for i in temp_l:
        e = len(i)
        f = sum(i)
        if e>=q:
            if f>sum(w):
                 w = i
                 q = e
    t = sum(w)
    return(t)

q = int(input())
for i in range(q):
    b = input()
    a = input().split()
    s = []
    for i in a:
        s.append(int(i))
    print(ans(s))
