from sys import stdin, stdout
import math
mod = 10**9+7
for _ in range(int(stdin.readline())):
    n = int(stdin.readline())
    arr = list(map(int, stdin.readline().split()))
    ans = 0
    temp = True
    t1 = arr[0]
    t2 = 0
    if arr[0]<0:
        temp = False
    for i in range(n):
        if t1>=0:
            if arr[i]<0:
                ans+=t1
                t1 = arr[i]
            else:
                t1 = max(t1, arr[i])
        elif t1<0:
            if arr[i]>=0:
                ans+=t1
                t1 = arr[i]
            else:
                t1 = max(t1, arr[i])
    ans+=t1
    stdout.write(str(ans)+"\n")