#include <bits/stdc++.h>
using namespace std;
int n, t;
int main() {
  ios_base::sync_with_stdio(false);
  long long x, cur;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> x;
    cur = x;
    long long ans = 0;
    for (int i = 1; i < n; ++i) {
      cin >> x;
      if ((cur < 0 && x > 0) || (cur > 0 && x < 0)) {
        ans += cur;
        cur = x;
      } else {
        cur = max(cur, x);
      }
    }
    ans += cur;
    cout << ans << '\n';
  }
  return 0;
}
