def solve():
    n = int(input())
    lst = list(map(int,input().split()))
    x = []
    y = []
    cur = 0
    x.append(lst[0])
    for i in range(1 , n):
        if(x[-1] * lst[i] < 0):
            y.append(x)
            x = []
        x.append(lst[i])
        #print(x)
    y.append(x)
    #print(y)
    #print(x)
    for i in range(len(y)):
        cur += max(y[i])
    print(cur)
t = int(input())
for i in range(t):
    solve()
