import sys
input = sys.stdin.readline


def main():
    t = int(input())
    for _ in range(t):
        N = int(input())
        A = [int(x) for x in input().split()]

        ans = 0
        pf = False
        if A[0] > 0:
            pf = True

        tmp = []
        for a in A:
            if pf:
                if a < 0:
                    pf = False
                    ans += max(tmp)
                    tmp.clear()
                    tmp.append(a)
                else:
                    tmp.append(a)
            else:
                if a > 0:
                    pf = True
                    ans += max(tmp)
                    tmp.clear()
                    tmp.append(a)
                else:
                    tmp.append(a)
        if tmp:
            ans += max(tmp)
        print(ans)


if __name__ == '__main__':
    main()


