t = int(input())

for i in range(t) :
    n = int(input())
    a = list(map(int,input().strip().split()))[:n]

    seg_max = []
    max_ele = a[0]
    out = 0

    for j in range(n-1) :
        if a[j] > 0 and a[j+1] > 0 :
            max_ele = max(a[j],a[j+1],max_ele)
            # print('not append')
            # print(max_ele)
        elif a[j] < 0 and a[j+1] < 0 :
            max_ele = max(a[j],a[j+1],max_ele)
            # print('not append')
            # print(max_ele)
        else :
            if max_ele == 0 :
                seg_max.append(a[j])
                out += a[j]
                # print('append')
                # print(a[j])
            else :
                seg_max.append(max_ele)
                out += max_ele
                max_ele = a[j+1]
                # print('append') #-2 8 3 8 -4 -15 5 -2 -3 1
                # print(max_ele)
            
    seg_max.append(max_ele)
    out += max_ele

    print(out)