#include <bits/stdc++.h>
using namespace std;
const long long MAXX = 2e5 + 10, inf = 1e18 + 10;
long long T, n, a[MAXX], ans, mx;
int jump(int x) {
  int l = x;
  mx = -inf;
  while (((a[x] < 0 && a[l] < 0) || (a[x] > 0 && a[l] > 0)) && l < n)
    mx = max(a[l], mx), l++;
  return l;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> T;
  while (T--) {
    cin >> n;
    ans = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i = jump(i)) jump(i), ans += mx;
    cout << ans << endl;
  }
}
