#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    bool pos = true;
    long long mn = -LONG_LONG_MAX;
    long long mx = 0;
    if (a[0] < 0) {
      pos = false;
      mn = a[0];
    } else {
      mx = a[0];
    }
    long long total = 0;
    for (int i = 1; i < n; i++) {
      if (a[i] > 0) {
        if (pos == false) {
          total += mn;
          mn = -LONG_LONG_MAX;
          pos = true;
        }
        mx = max(mx, a[i]);
      } else {
        if (pos == true) {
          total += mx;
          mx = 0;
          pos = false;
        }
        mn = max(mn, a[i]);
      }
    }
    if (pos == false) {
      total += mn;
    } else {
      total += mx;
    }
    cout << total << "\n";
  }
  return 0;
}
