#include <bits/stdc++.h>
using namespace std;
long long a, b, a1, b1, b2, e, a2, a3, b3, c, q, n, m, i, j, w, k, o, p, l, t,
    r, y, f, mx, qw, rt, qr;
long long A[1000001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (y = 0; y < t; y++) {
    cin >> n;
    mx = -1000000000000000;
    a = 0;
    for (i = 0; i < n; i++) {
      cin >> A[i];
      if (A[i] < 0 && A[i - 1] < 0 || A[i] >= 0 && A[i - 1] >= 0 || i == 0)
        mx = max(mx, A[i]);
      else {
        a += mx;
        mx = A[i];
      }
    }
    a += mx;
    cout << a << "\n";
  }
}
