testcase = int(input())
for t in range(testcase):
    n = int(input())
    arr = list(map(lambda x :int(x), input().split()))
    res = 0
    temp = arr[0]
    for i in range(1,n,1):
        #print("i",i,arr[i])
        if arr[i]*temp < 0:
            res += temp
            temp = arr[i]
            #print("res:",res)
        else:
            if arr[i] > temp:
                temp = arr[i]
    res += temp
    print(res)