for _ in range(int(input())):
    n = int(input())
    a = [int(x) for x in input().split()]
    max_sum = 0
    cur_num = float("-inf")
    cur_pos = False
    for i in range(n):
        if i==0:
            cur_pos = False
            if a[i]>0:
                cur_pos = True
            cur_num = a[i]
        elif a[i] < 0 and cur_pos == False:
            cur_pos = False
            if a[i]>cur_num:
                cur_num = a[i]
        elif a[i]<0 and cur_pos == True:
            max_sum+=cur_num
            cur_pos = False
            cur_num = a[i]
        elif a[i]>0 and cur_pos == True:
            if a[i]>cur_num:
                cur_num = a[i]
        elif a[i]>0 and cur_pos == False:
            cur_pos = True
            max_sum+=cur_num
            cur_num = a[i]
        # print(max_sum)
    max_sum+=cur_num
    print(max_sum)
        
                
            
