from sys import stdin, stdout
from collections import Counter
import math


def main2():
    n = input()
    finaloutput=[]
    for i in range(int(n)):
        asdf=input()
        array=input()
        arr2 = [int(x) for x in array.split()]
        output=[]
        num=arr2[0]
        for i in range(1,len(arr2)):
            if math.copysign(1,arr2[i]) != math.copysign(1,num):
                output.append(num)
                num=arr2[i]
            elif arr2[i]>num:
                num=arr2[i]
        output.append(num)
        finaloutput.append(str(sum(output)))
    for i in finaloutput:
        stdout.write(i + '\n')
    return()
# call the main method 
if __name__ == "__main__": 
   main2()    