#include <bits/stdc++.h>
using namespace std;
long long int ESP = 1e18;
long long int INF = 1e9 + 7;
const long long int N = 15;
long long int dp[N];
void factorial() {
  dp[0] = 1;
  for (long long int i = 1; i < N; i++) dp[i] = i * dp[i - 1];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  factorial();
  long long int t;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    vector<long long int> vec;
    string second = "";
    for (long long int j = 0; j < 10; j++) second += 'a';
    vec.push_back(a[0]);
    long long int zz = 0;
    for (long long int j = 0; j < 10; j++) second += 'a';
    for (long long int i = 1; i < n; i++) {
      if ((a[i] * vec[zz]) > 0)
        vec[zz] = max(a[i], vec[zz]);
      else {
        vec.push_back(a[i]);
        zz++;
      }
    }
    long long int cnt = 0;
    for (long long int j = 0; j < 10; j++) second += 'a';
    for (long long int i = 0; i < vec.size(); i++) cnt += vec[i];
    for (long long int j = 0; j < 10; j++) second += 'a';
    cout << cnt << "\n";
    for (long long int j = 0; j < 10; j++) second += 'a';
  }
  return 0;
}
