for i in range(int(input())):
    a = input()
    seq = [int(x) for x in input().strip().split()]

    subseq = [[seq[0]]]
    index = 0
    for i in range(1, len(seq)):
        if (seq[i-1] > 0 and seq[i] > 0) or \
           (seq[i-1] < 0 and seq[i] < 0):
           subseq[index].append(seq[i])
        else:
            subseq.append([seq[i]])
            index += 1

    total = 0
    for ss in subseq:
        total += max(ss)

    print(total)
