for _ in range(int(input())):
    n = int(input())
    lst = list(map(int,input().split()))
    lst2 = []
    i = 0
    j = 0
    while j != n:
        if lst[i] > 0 and lst[j] > 0:
            j += 1
        
        elif lst[i] < 0 and lst[j] < 0:
            j += 1
        else:
            lst2.append(lst[i:j])
            i = j
    lst2.append(lst[i:j])
    cnt = 0
    for i in lst2:
            cnt += max(i)
    print(cnt)