#include <bits/stdc++.h>
using namespace std;
bool compare(std::pair<int, int> i, pair<int, int> j) {
  return i.second < j.second;
}
int sgn(int x) {
  if (x > 0)
    return 1;
  else
    return -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, c = 0, p = 0, l = 0, c2 = 0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    ;
    for (int i = 0; i < n; i++) {
      c = a[i];
      int j;
      for (j = i; j < n && sgn(a[i]) == sgn(a[j]); j++) {
        c = max(a[j], c);
      }
      p += c;
      i = j - 1;
    }
    cout << p << endl;
  }
}
