# cook your dish here
from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left 
from bisect import bisect_right
 
def L():
    return list(map(int, stdin.readline().split()))
 
def In():
    return map(int, stdin.readline().split())
 
def I():
    return int(stdin.readline())
 
P = 1000000007
def main():
    for t in range(I()):
        n = I()
        arr = L()
        sm, v = 0, arr[0]
        flag = 0
        if arr[0] < 0:
            flag = 0
        else:
            flag = 1
        for i in range(1, n):
            if flag and arr[i] < 0:
                sm += v
                flag = 0 
                v = arr[i]
            elif flag and arr[i] > 0:
                v = max(v, arr[i])
            elif (not flag) and arr[i] < 0:
                v = max(v, arr[i])
            else:
                sm += v
                flag = 1 
                v = arr[i]
        sm += v
        print(sm)
    
if __name__ == '__main__':
    main()
