# -*- coding: utf-8 -*-
"""
Created on Tue Mar 31 08:36:04 2020

@author: CronuS
"""

k = list(map(int, input().split()))
t = k[0];
for i in range(t):
    s = list(map(int, input().split()))
    n = list(map(int, input().split()))
    maxminus = -1000000000000
    maxplus = 0
    flag = 0
    summa = 0
    for i in range(len(n)):
        if (i == 0):
            if (n[i] > 0):
                flag = 1
                maxplus = max(maxplus, n[i])
            else:
                flag = -1
                maxminus = max(maxminus, n[i])
        else:
            if (n[i] > 0):
                if (flag == 1):
                    maxplus = max(maxplus, n[i])
                else:
                    summa = summa + maxminus
                    flag = 1
                    maxplus = n[i]
            else:
                if (flag == -1):
                    maxminus = max(maxminus, n[i])
                else:
                    summa = summa + maxplus
                    flag = -1
                    maxminus = n[i]
    if (flag == 1):
        summa = summa + maxplus
    else:
        summa = summa + maxminus
    print(summa)
        