from sys import stdin
from collections import Counter, deque
input = stdin.buffer.readline

T = int(input())
for _ in range(T):
    n = int(input())
    ls = list(map(int, input().split()))
    
    sm, tl = 0, []
    for i, u in enumerate(ls):
        tl.append(u)
        if i == n-1 or u*ls[i+1] < 0:
            sm += max(tl)
            tl.clear()
    print(sm)