#import math
#from functools import lru_cache
#import heapq
#from collections import defaultdict
#from collections import Counter
#from sys import stdout
#from sys import setrecursionlimit
from sys import stdin
input = stdin.readline
for ti in range(int(input().strip())):
    n = int(input().strip())
    a = [int(x) for x in input().strip().split()]
    s = 0
    prev = a[0]
    for ai in a:
        #print(prev)
        if((ai<0) == (prev<0)):
            prev = max(prev, ai)
        else:
            s += prev
            prev = ai
    s += prev
    print(s)
