#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  long long s, m;
  long n, i, j;
  cin >> t;
  while (t--) {
    cin >> n;
    long long a[n];
    s = 0;
    for (i = 0; i < n; i++) cin >> a[i];
    i = 0;
    while (i < n) {
      m = a[i];
      j = i + 1;
      if (a[i] > 0)
        while (j < n && a[j] > 0) {
          m = max(m, a[j]);
          j++;
        }
      else
        while (j < n && a[j] < 0) {
          m = max(m, a[i]);
          j++;
        }
      i = j;
      s += m;
    }
    cout << s << endl;
  }
  return 0;
}
