import sys
input = lambda:sys.stdin.readline()

int_arr = lambda: list(map(int,input().split()))
str_arr = lambda: list(map(str,input().split()))
get_str = lambda: map(str,input().split())
get_int = lambda: map(int,input().split())
get_flo = lambda: map(float,input().split())

mod = 1000000007

def solve(n,arr):
    tot = 0
    if arr[0] > 0:
        fg = 0
        mx = arr[0]
    else:
        fg = 1
        mi = arr[0]

    for i in range(1,n):
        if fg == 1:
            if arr[i] > 0:
                fg = 0
                tot += mi
                mx = arr[i]
            else:
                if arr[i] > mi:
                    mi = arr[i]

        else:
            if arr[i] < 0:
                fg = 1
                tot += mx
                mi = arr[i]
            else:
                if arr[i] > mx:
                    mx = arr[i]


    if arr[-1] < 0:
        tot += mi
    else:
        tot += mx

    print(tot)






for _ in range(int(input())):
    n = int(input())
    arr = int_arr()
    solve(n,arr)

