t = int(input())
for _ in range(t):
    n = int(input())
    a = map(int, input().split())
    s = 0
    
    max_pos_cur = None
    max_neg_cur = None
    prev_sign_pos_flag = None
    for i in a:
        if prev_sign_pos_flag is None:
            if i < 0:
                max_neg_cur = i
                prev_sign_pos_flag = 0
            else:
                max_pos_cur = i
                prev_sign_pos_flag = 1
        else:
            if i < 0:
                if max_neg_cur is None:
                        max_neg_cur = i
                if prev_sign_pos_flag == 0:
                    max_neg_cur = max(i, max_neg_cur)
                else:
                    s += max_pos_cur
                    max_pos_cur = None
                prev_sign_pos_flag = 0
            else:
                if max_pos_cur is None:
                        max_pos_cur = i
                if prev_sign_pos_flag == 1:
                    max_pos_cur = max(i, max_pos_cur)
                else:
                    s += max_neg_cur
                    max_neg_cur = None
                prev_sign_pos_flag = 1
                
    if prev_sign_pos_flag == 0:
        s += max_neg_cur
    else:
        s += max_pos_cur
    print(s)