from bisect import bisect_left as lower_bound, bisect_right as upper_bound
from sys import stdin, stdout
from collections import defaultdict

inf = 10**17

def solve(arr, n):
    pass

def main():
    t = int(input())

    for _ in range(t):
        n = int(input())
        arr = list(map(int, input().strip().split()))
        
        pos, neg = -inf, -inf


        for i, num in enumerate(arr):
            if num > 0:
                new_pos = num+(neg if neg != -inf else 0)

                if i >0 and arr[i-1] > 0: pos = max(pos, new_pos)
                else: pos = new_pos

                #print(num, pos)

            else:
                new_neg = num+(pos if pos != -inf else 0)

                if i >0 and arr[i-1] < 0: neg = max(neg, new_neg)
                else: neg = new_neg
                #print(num, neg)

        if arr[-1] < 0: print(neg)
        else: print(pos)


if __name__ == "__main__": main()
