#include <bits/stdc++.h>

using namespace std;

int main(){
	
	int t;
	cin >> t;

	while(t--){
		int n;
		cin >> n;

		int a[n] {0};
		
		for(int i=0;i<n;i++){
			cin >> a[i];
		}

		 vector < set <int> > v;

		 set <int> s;
		 s.insert(a[0]);

		 for(int i=1;i<n;i++){

		 	if(a[i-1]*a[i] >=0){
		 		s.insert(a[i]);
		 	}
		 	else{
		 		v.push_back(s);
		 		s.clear();
		 		s.insert(a[i]);
		 	}

		 }

		 v.push_back(s);

		/* for(int i=0;i<v.size();i++){
		 	
		 	for(auto it:v[i]){
		 		cout << it << " ";
		 	}

		 	cout << endl;
		 } */

		 int sum=0;

		 for(int i=0;i<v.size();i++){
		 	sum = sum + *(v[i].rbegin());
		 }

		 cout << sum << endl;


	}
	
	return 0;
}