def main():
    for _ in range(int(input())):
        input()
        poz = neg = (0, 0, 0)
        for x in map(int, input().split()):
            if x > 0:
                poz = max(poz, (neg[0] + 1, neg[1] + x, x))
            else:
                neg = max(neg, (poz[0] + 1, poz[1] + x, x))
        print(max(poz, neg)[1])


if __name__ == '__main__':
    main()
