t = int(input());
for test in range(t):
    n = int(input());
    arr = list(map(int,input().split()));
    flagn = False;
    flagp = False;
    lp = 0;
    ln = 0;
    res = [];
    if(arr[0]>0):
        lp = arr[0];
        flagp = True;
    else:
        ln = arr[0];
        flagn = True;
    for i in range(1,n):
        if(flagp):
            if(arr[i]>0):
                lp = max(lp,arr[i]);
            else:
                res.append(lp);
                flagn=True;
                flagp=False;
                ln=arr[i]; 

        else:
            if(arr[i]<0):
                ln = max(ln,arr[i]);
            else:
                res.append(ln);
                flagp=True;
                flagn=False;
                lp=arr[i];
    if(flagp):
        res.append(lp);
    if(flagn):
        res.append(ln);
    print(sum(res));
            
