def maximumsub(l):
    
    summ=0;
    choose=None;
    for i in l:
        if choose==None:
            choose=i;
        elif choose*i<0:
            
            summ+=choose;
            choose=i;
        elif i>choose:
            choose=i;
    
    summ+=choose;
    return summ;

t=int(input())
for i in range(t):
    n=int(input());
    print(maximumsub([int(i) for i in input().split()]));