#include <bits/stdc++.h>
using namespace std;
const long long INF = ~0ull >> 2;
int _;
void solve() {
  int n;
  scanf("%d", &n);
  int a[200005];
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  long long ans = 0;
  int mid = 0, flag = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] / abs(a[i]) != flag) {
      flag = a[i] / abs(a[i]);
      ans += mid;
      mid = a[i];
    } else {
      mid = max(mid, a[i]);
    }
  }
  ans += mid;
  cout << ans << endl;
}
int main() {
  for (scanf("%d", &_); _; _--) {
    solve();
  }
  return 0;
}
