#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
  int q, n, mx, L;
  long long sum;
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    mx = a[1];
    if (a[1] < 0)
      L = 0;
    else
      L = 1;
    sum = 0;
    for (int i = 2; i <= n; i++) {
      if (L == 0) {
        if (a[i] < 0)
          mx = max(mx, a[i]);
        else {
          L = 1;
          sum += mx;
          mx = a[i];
        }
      } else {
        if (a[i] > 0)
          mx = max(mx, a[i]);
        else {
          L = 0;
          sum += mx;
          mx = a[i];
        }
      }
    }
    sum += mx;
    cout << sum << "\n";
  }
  return 0;
}
