#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 10;
long long int a[mx];
bool mn(int x) {
  if (x < 0) return 1;
  return 0;
}
int main() {
  long long int t, n, ans = 0, mx;
  bool b;
  cin >> t;
  while (t--) {
    ans = 0;
    b = 0;
    cin >> n;
    cin >> a[0];
    b = mn(a[0]);
    mx = a[0];
    for (int i = 1; i < n; i++) {
      cin >> a[i];
      if (mn(a[i]) != b) {
        ans += mx;
        b = !b;
        mx = a[i];
      } else {
        mx = max(mx, a[i]);
      }
    }
    ans += mx;
    cout << ans << endl;
  }
  return 0;
}
