#include <bits/stdc++.h>
using namespace std;
void ffast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  ffast();
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long a[n];
    vector<long long> v;
    for (int i = 0; i < n; i++) cin >> a[i];
    bool sign = 0;
    long long p_max = INT_MIN, n_max = INT_MIN;
    int i = 0;
    long long sum = 0;
    while (i < n) {
      while (i < n and a[i] > 0) {
        p_max = max(p_max, a[i]);
        n_max = INT_MIN;
        i++;
      }
      if (p_max != INT_MIN) sum += p_max;
      while (i < n and a[i] < 0) {
        n_max = max(n_max, a[i]);
        p_max = INT_MIN;
        i++;
      }
      if (n_max != INT_MIN) sum += n_max;
    }
    cout << sum << "\n";
  }
}
