MOD = 10**9+7
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
def main():
    test = int(input())
    for iteration in range(test):
        n = int(input())
        arr = [int(i) for i in input().split()]
        sum = 0
        if arr[0] > 0:
            max_pos = arr[0]
            max_neg = MOD*(-1)
            prev = "pos"
        else:
            max_neg = arr[0]
            max_pos = 0
            prev = "neg"
        for i in range(1,n):
            if arr[i] > 0:
                if prev == "pos":
                    if arr[i] > max_pos:
                        max_pos = arr[i]
                        #print(max_pos)
                else:
                    sum += max_neg
                    max_pos = arr[i]
                    max_neg = MOD*(-1)
                prev = "pos"
            else:
                #print(2222)
                if prev == "neg":
                    if arr[i] > max_neg:
                        max_neg = arr[i]
                        #print(max_neg)
                else:
                    sum += max_pos
                    max_neg = arr[i]
                    max_pos = 0
                prev = "neg"
        #print(max_pos,max_neg)
        if prev == "pos":
            sum += max_pos
        else:
            #print(1000)
            sum += max_neg
        print(sum)


if __name__ == '__main__':
    main()