def max_sum (num):
    max_list = []
    curr_num = int(num[0])
    positive = None
    if curr_num > 0:
        positive = 1
    else :
        positive = 0
    for i in num :
        if positive and int(i) > 0 :
            if int(i) > curr_num :
                curr_num = int(i)
        elif positive and int(i) < 0:
            positive = 0
            max_list.append(curr_num)
            curr_num = int(i)
        elif int(i) < 0 and int(i) > curr_num :
            curr_num = int(i)
        elif int(i) > 0 :
            positive = 1 
            max_list.append(curr_num)
            curr_num = int(i)
    max_list.append(curr_num)
    return sum(max_list)
for i in range(int(input())):
    r = input()
    print(max_sum(input().split()))