#include <bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 13;
long long a[maxN];
inline int sign(int x) {
  if (x < 0) return -1;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    int neg_ind = -1, pos_ind = -1;
    for (int i = 1; i <= N; i++) {
      cin >> a[i];
      if (a[i] > 0 && pos_ind == -1) {
        pos_ind = i;
      }
      if (a[i] < 0 && neg_ind == -1) {
        neg_ind = i;
      }
    }
    long long now_sign = 1, tsum = 0, tmax = -1e9 - 13;
    long long pos_max = 0, neg_max = 0;
    int pos_length = 0, neg_length = 0;
    for (int i = pos_ind; i <= N; i++) {
      if (now_sign == sign(a[i])) {
        tmax = max(tmax, a[i]);
      } else {
        pos_length++;
        tsum += tmax;
        tmax = a[i];
        now_sign *= -1;
      }
    }
    pos_max = tsum + tmax;
    now_sign = -1;
    tsum = 0;
    tmax = -1e9 - 13;
    for (int i = neg_ind; i <= N; i++) {
      if (now_sign == sign(a[i])) {
        tmax = max(tmax, a[i]);
      } else {
        neg_length++;
        tsum += tmax;
        tmax = a[i];
        now_sign *= -1;
      }
    }
    neg_max = tsum + tmax;
    if (neg_length > pos_length) {
      cout << neg_max << endl;
    } else if (neg_length < pos_length) {
      cout << pos_max << endl;
    } else {
      cout << max(pos_max, neg_max) << endl;
    }
  }
  return 0;
}
