if __name__ == "__main__":
    t = int(input())
    l = []
    for i in range(t):
        n = int(input())
        arr = []
        k = input().split()
        for j in range(n):
            arr.append(int(k[j]))
        #print(type(arr[0]))
        max_min = - pow(10, 9)
        q= max_min
        # print(min)
        # print(-3>-7)
        sum = 0
        for j in range(n-1):
            k = (arr[j] > 0 and arr[j+1] < 0)
            s = (arr[j] < 0 and arr[j+1] > 0)
            
            #print("jjjjjjjjj ",arr[j]>max_min)
            #print(max_min, " issss ", arr[j])
            
            if k or s:
                
                if max_min < arr[j]:
                    sum += arr[j]
                else:
                    sum += max_min
                max_min = arr[j+1]
                #print(sum)
            elif max_min < arr[j]:
                #print("kkkkkk")
                max_min = arr[j]
            #print("Suuum ",sum)
            
        #print("Final sum ",max_min)

        if arr[n-1] > max_min:
            sum += arr[n-1]
        else:
            sum += max_min
        l.append(sum)

    for i in range(t):
        print(l[i])
