#include <bits/stdc++.h>
using namespace std;
inline void io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
}
const int s = 2e5 + 6;
long long a[s];
int main() {
  io();
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    int m = 1;
    long long sum = 0;
    (a[0] > 0 ? m = 1 : m = -1);
    for (int i = 0; i < n; ++i) {
      if (a[i] > 0) {
        long long mx = 0;
        while (a[i] > 0 && i < n) {
          mx = max(mx, a[i]);
          i++;
        }
        --i;
        sum += mx;
      } else {
        long long mx = -1e10;
        while (a[i] < 0 && i < n) {
          mx = max(mx, a[i]);
          i++;
        }
        --i;
        sum += mx;
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
