def arrange(lis):
    dic = [0]
    for num in lis:
        if num < 0 and dic[-1] == 0:
            dic.append(num)
        elif num < 0 and dic[-1] < num and dic[-1] < 0:
            dic[-1] = num
        elif num < 0 and dic[-1] > 0:
            dic.append(num)
        elif num > 0 and dic[-1] == 0:
            dic.append(num)
        elif num > 0 and dic[-1] < num and dic[-1] > 0:
            dic[-1] = num
        elif num > 0 and dic[-1] < 0:
            dic.append(num)
    return sum(dic)

for t in range(int(input())):
    k = int(input())
    lis =list(map(int, input().split()))
    print(arrange(lis))