for _ in range(int(input())):
    n = int(input())
    nl = list(map(int, input().split()))
    mnl = [nl[0]]
    for i in range(1, n):
        if (mnl[-1] < 0) == (nl[i] < 0):
            mnl[-1] = max(mnl[-1], nl[i])
        else:
            mnl.append(nl[i])
    print(sum(mnl))
