testcases = int(input())
for i in range(testcases):
    n = int(input())
    l = list(map(int, input().strip().split(" ")))
    # positive to negative Traversal
    pOn = []
    p = 0
    for j in range(n):
        if l[j] > 0 and len(pOn) == 0:
            pOn.append(l[j])
            p += 1
        else:
            if p != 0:
                if l[j] > 0:
                    if p % 2 == 0:
                        pOn.append(l[j])
                        p += 1
                    else:
                        if p % 2 != 0:
                            if l[j] > pOn[-1]:
                                pOn[-1] = l[j]
                            else:
                                pass
                else:
                    if l[j] < 0:
                        if p % 2 != 0:
                            pOn.append(l[j])
                            p += 1
                        else:
                            if p % 2 == 0:
                                if l[j] > pOn[-1]:
                                    pOn[-1] = l[j]
                                else:
                                    pass

    # negative to posit
    nOp = []
    m = 0
    for k in range(n):
        if l[k] < 0 and len(nOp) == 0:
            nOp.append(l[k])
            m += 1
        else:
            if m != 0:
                if l[k] > 0:
                    if m % 2 != 0:
                        nOp.append(l[k])
                        m += 1
                    else:
                        if l[k] > nOp[-1]:
                            nOp[-1] = l[k]
                        else:
                            pass
                else:
                    if l[k] < 0:
                        if m % 2 == 0:
                            nOp.append(l[k])
                            m += 1
                        else:
                            if l[k] > nOp[-1]:
                                nOp[-1] = l[k]
                            else:
                                pass

    if len(pOn) > len(nOp):
        print(sum(pOn))
    else:
        print(sum(nOp))










