t = int(input())
for test in range(t):
    n = int(input())
    lst = list(map(int,input().split()))
    sum1 = 0
    a = lst[0]
    p = 0
    if a > 0:
        p = 1
    lst1 = []
    lst1.append(a)
    for i in range(1,n):
        if lst[i] > 0 and p == 1:
            lst1.append(lst[i])
        elif lst[i] < 0 and p == 0:
            lst1.append(lst[i])
        else:
            m = max(lst1)
            sum1 += m
            lst1 = []
            if i <= n-1:
                a = lst[i]
                p = 0
                if a > 0:
                    p = 1
                lst1.append(a)
    l = len(lst1)
    if l > 0:
        m = max(lst1)
        sum1 += m
    print(sum1)
