for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    final = a[-1]
    a.append(-final) # to make sure it counts the last element
    res = 0; maxscore = a[0]
    for i in range(1,len(a)):
        if a[i]*a[i-1] > 0: # same parity
            maxscore = max(a[i], maxscore) # works b/c want max when > 0 and < 0 
        else: #switch parity so need to add to the result
            res+=maxscore
            maxscore = a[i]
    print(res)
            
            
                