def is_opposite(i, j):
    if i > 0 and j > 0:
        return False
    if i < 0 and j < 0:
        return False
    return True

class Node:
    def __init__(self, st_sign):
        self.sum = 0
        self.len = 0
        self.last = not st_sign

    def add(self, n):
        if self.len == 1 and self.sum < n and self.last == n > 0:
            self.sum = n
            return
        if len != 0:
            if n > 0 and self.last:
                return
            if n < 0 and not self.last:
                return
        self.sum = self.sum + n
        self.len = self.len + 1
        self.last = n > 0 

T = int(input())
while T > 0:
    T = T - 1
    n = int(input())
    nums = list(map(int, input().split(" ")))
    i = 0
    pos_st = Node(True)
    neg_st = Node(False)
    while i < n:
        pos_st.add(nums[i])
        neg_st.add(nums[i])
        i = i + 1

    if pos_st.len > neg_st.len:
        print(pos_st.sum)
    elif pos_st.len < neg_st.len:
        print(neg_st.sum)
    else:
        print(max(pos_st.sum, neg_st.sum))



