import sys
input = sys.stdin.readline

tc = int(input())
INF = 1000000005

for tx in range(tc):
    n = int(input())
    a = list(map(int,input().split()))
    
    ma=-INF
    b=0
    for i in range(0,len(a)):
        if i and a[i-1]*a[i]<0:
            b=b+ma
            ma=-INF
        ma=max(ma,a[i])
    b=b+ma

    print(b)



