total = int(input()) 

for _ in range(total):
    n = list(map(int, input().split()))[0]
    seq = list(map(int, input().split()))
    current = float('-inf')
    best =0
    for i in range(n-1):
        if seq[i] * seq[i+1] > 0:
            current = max(current, seq[i], seq[i+1])
        elif seq[i] > 0 and seq[i+1] < 0:
            current = max(current, seq[i])
            best += current
            current = float('-inf')
        else:
            current = max(current, seq[i])         
            best += current
            current = float('-inf')
    if current == float('-inf'):
        print(best + seq[-1])
        continue
    print(best + current)