#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long x, last, now, minn = 1e9, maxx = -1e9, ans = 0;
    cin >> x;
    last = maxx = minn = x;
    if (x < 0)
      now = -1;
    else
      now = 1;
    for (long long i = 2; i <= n; ++i) {
      cin >> x;
      if ((x > 0) ^ (last > 0)) {
        ans += maxx;
        maxx = x;
        minn = x;
      }
      minn = min(minn, x);
      maxx = max(maxx, x);
      last = x;
    }
    ans += maxx;
    cout << ans << endl;
  }
  return 0;
}
