for _ in range(int(input())):
    int(input())
    a = [int(i) for i in input().split()]

    newa = []
    mxpos = 0
    mxneg = -1e9
    positive_now = True
    for i, ai in enumerate(a):
        if ai > 0:
            if not positive_now:
                newa.append(mxneg)
            mxpos = max(mxpos, ai)
            positive_now = True
            mxneg = -1e9
        if ai < 0:
            if positive_now:
                newa.append(mxpos)
            mxneg = max(mxneg, ai)
            positive_now = False
            mxpos = 0
    if positive_now:
        newa.append(mxpos)
    else:
        newa.append(mxneg)

    print(int(sum(newa)))
