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

# In[16]:


import fileinput

t = int(input())
for i in range(t):
    n = int(input())
    a = [int(x) for x in input().split(' ')]
    max_pos = 0
    pos_len = 0
    max_neg = 0
    neg_len = 0
    for x in a:
        if x > 0:
            if pos_len < neg_len + 1 or (pos_len == neg_len + 1 and max_pos < max_neg + x):
                pos_len = neg_len + 1
                max_pos = max_neg + x
        else:
            if neg_len < pos_len + 1 or (pos_len + 1 == neg_len and max_neg < max_pos + x):
                neg_len = pos_len + 1
                max_neg = max_pos + x
    if pos_len > neg_len or (pos_len == neg_len and max_pos > max_neg):
        print(max_pos)
    else:
        print(max_neg)
            


# In[ ]:




