#https://codeforces.com/contest/1343/problem/C
#C. Alternating Subsequence
t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    i = 0
    al = []
    b = []
    c = []
    #print(a)
    #print(n)
    #print(a[i])
    while i < n:
        while i < n and a[i] < 0:
            b.append(a[i])
            i += 1
            #print("!")
        if b:
            al.append(b)
            b = []
        while i < n and a[i] > 0:
            c.append(a[i])
            i += 1
            #print("?")
        if c:
            al.append(c)
            c = []
    #print(al)
    su = 0
    for j in range(len(al)):
        su += max(al[j])
    print(su)
            
