"""
Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
"""

if __name__== "__main__":
    t = int(input())
    for _ in range(t):
        n = int(input())
        a = [int(x) for x in input().split()]
        res_pos = [-1]
        res_neg = [1]
        for x in a:
            # Checking res_pos
            if x * res_pos[-1] < 0:
                res_pos.append(x)
            elif x > res_pos[-1]:
                res_pos[-1] = x
            # Checking res_neg
            if x * res_neg[-1] < 0:
                res_neg.append(x)
            elif x > res_neg[-1]:
                res_neg[-1] = x

        res = res_pos
        if len(res_pos) < len(res_neg):
            res = res_neg
        res_sum = 0
        for i in range(1, len(res)):
            res_sum += res[i]
        print(res_sum)



