#include <bits/stdc++.h>
using namespace std;
void solveC() {
  long long int sum = 0;
  long long int take = 0;
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n; ++i) {
    long long int a;
    cin >> a;
    if (a * take > 0) {
      take = max(take, a);
    } else {
      sum += take;
      take = a;
    }
  }
  cout << sum + take << endl;
}
signed main() {
  long long int t;
  cin >> t;
  for (long long int i = 0; i < t; ++i) {
    solveC();
  }
}
