#include <bits/stdc++.h>
using namespace std;
long long int t, n, a[300000], ans = 0;
int main() {
  cin >> t;
  for (long int j = 0; j < t; j++) {
    cin >> n;
    ans = 0;
    long int f = 0;
    cin >> a[0];
    for (long int i = 1; i < n; i++) {
      cin >> a[i];
      if (a[i] > 0 && a[i - 1] < 0) {
        sort(a + f, a + i);
        ans += a[i - 1];
        f = i;
      }
      if (a[i] < 0 && a[i - 1] > 0) {
        sort(a + f, a + i);
        ans += a[i - 1];
        f = i;
      }
    }
    sort(a + f, a + n);
    ans += a[n - 1];
    cout << ans << endl;
  }
  return 0;
}
