T = int(input())
for t in range(T):
    n = int(input())
    arr = list(map(int,input().split()))
    flag = -1
    last_positive = 0
    minn = min(arr)
    last_negative = minn
    lis = []
    for i in arr:
        # print(i,flag,last_positive)
        if i>last_positive:
            if flag==0:
                lis.append(last_negative)
                last_negative = minn
            last_positive = i
            flag=1
        elif 0>i>=last_negative:
            if flag==1:
                lis.append(last_positive)
                last_positive = 0
            last_negative = i
            
            flag = 0
    if flag==0:
        lis.append(last_negative)
    if flag==1:
        lis.append(last_positive)
    
    print(sum(lis))
            
    