#include <bits/stdc++.h>
using namespace std;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
int main() {
  ios_base::sync_with_stdio(0);
  int t, i, j, k, p, q, r, y, u, v, n, m;
  double x;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> a(n);
    for (i = 0; i < n; i++) cin >> a[i];
    int max_n, max_p;
    int ni = -1, pi = -1;
    vector<int> pos, neg;
    for (i = 0; i < n; i++) {
      if (a[i] < 0) {
        ni++;
      } else {
        pi++;
      }
    }
    if (ni == -1 || pi == -1) {
      cout << *max_element(a.begin(), a.end()) << endl;
    } else {
      i = 0;
      while (i < n) {
        if (a[i] < 0) {
          max_n = a[i];
          while (a[i] < 0 && i < n) {
            max_n = max(a[i], max_n);
            i++;
          }
          neg.push_back(max_n);
        }
        if (a[i] > 0) {
          max_p = a[i];
          while (a[i] > 0 && i < n) {
            max_p = max(a[i], max_p);
            i++;
          }
          pos.push_back(max_p);
        }
      }
      if (neg.size() > pos.size()) {
        neg.pop_back();
      }
      if (pos.size() > neg.size()) {
        pos.pop_back();
      }
      long long int p_sum = 0, n_sum = 0;
      for (i = 0; i < pos.size(); i++) p_sum += pos[i];
      for (i = 0; i < neg.size(); i++) n_sum += neg[i];
      cout << n_sum + p_sum << endl;
    }
  }
  return 0;
}
