def read(): return list(map(int,input().strip().split()))
for i in range(int(input())):
    n = int(input())
    arr = read()
    a = arr[0]
    s = 0
    for j in arr:
        if a*j <0:
            s+= a
            a = j
        else:a = max(a,j)
    print(s+a)
            
        