for _ in range(int(input())):
                                     
                             t=int(input())
                             
                             l=[int(x) for x in input().split()]
                             ll=[] 
                             ll.append(l[0])
                             for j in range(1,t):
                                                                
                                                  if l[j]>0 and l[j-1]<0:               
                                                                        ll.append(l[j])
                                                  elif l[j]<0 and l[j-1]>0:                
                                                                        ll.append(l[j])
                                                  elif l[j]>0 and l[j-1]>0:
                                                                        c=len(ll)-1               
                                                                        if l[j]>ll[c]:
                                                                                                          
                                                                                       ll[c]=l[j]                       
                                                  elif l[j]<0 and l[j-1]<0:
                                                                        c=len(ll)-1
                                                                        if l[j]>ll[c]:
                                                                                                        
                                                                                       ll[c]=l[j]
                                                  else:
                                                                                       ans=1
                                              
                                          
                                          
                             print(sum(ll))        