#!/usr/bin/env python
# coding: utf-8

# In[ ]:


t = int(input())
cnt = 0
while (cnt < t):
    cnt += 1
    n = int(input())
    a = [int(i) for i in input().split()]
    c = []
    lb, rb = 0, 0
    temp = []
    while (lb < n):
        temp.append(a[lb])
        #print(temp)
        rb = lb + 1
        while (rb < n):
            if a[rb - 1] * a[rb] > 0:
                temp.append(a[rb])
                rb += 1
            else:
                c.append(temp)
                temp = []   
                lb = rb
                break
        if temp:
            c.append(temp)
        #print(c)
        temp = []
        lb = rb
    result = 0
    #print(c)
    for i in c:
        result += max(i)
    print(result)
        

