for _ in range(int(input())):
    n = int(input())
    li = list(map(int, input().split()))
    lip = []
    lin = []
    # x = li[0]
    # if(x > 0):
    #     lip.append(x)
    # else:
    #     lin.append(x)

	
	
    c = 0
    nn, pp = 0, 0
    flag = True
    p = 0
    # c = 0
    i = 0
    t = 0
    while(i < n):
        t = li[i]
        q = 1
        flag = True
        if(li[i] < 0):
            flag = False
        while(flag == False and li[i] < 0 or (flag == True and li[i] > 0)):
            t = max(t, li[i])
            i += 1
            if(i >= n):
                break
        c += t
        if(i >= n):
            break
        flag = True
        # i -= 1
        
    print(c)
            
            
        
        # print(lip)
        # if(x > 0 and li[i] > 0):
        #     lip.append(li[i])
        #     pp = max(lip)
        # elif(x < 0 and li[i] < 0):
        #     lin.append(li[i])
        #     nn = max(lin)
            
            
        # else:
        #     x = li[i]
        #     if(x > 0):
        #         # nn = max(li[n])
        #         lin = []
        #         lip.append(x)
        #         c += nn
        #     else:
        #         # pp = max(lip)
        #         lip = []
        #         lin.append(x)
        #         c += pp
            # try:
            #     nn = max(lin)
            # except:
            #     nn = 0
            # try:
            #     pp = max(lip)
            # except:
            #     pp = 0
            # print(nn, pp)
            # c += nn + pp
            # lip = []
            # lin = []
    #         x = li[i]
    #     x = li[i]
    # print(c)