#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a;
    long long nowp = 0, nown = 0, flag = 0, maxpos = 0, maxneg = -1000000010;
    for (int i = 0; i < n; i++) {
      long long x;
      cin >> x;
      if (x > 0) {
        if (maxneg != -1000000010) {
          a.push_back(maxneg);
          maxneg = -1000000010;
        }
        maxpos = max(x, maxpos);
        if (i == n - 1) a.push_back(maxpos);
      } else if (x < 0) {
        if (maxpos != 0) {
          a.push_back(maxpos);
          maxpos = 0;
        }
        maxneg = max(maxneg, x);
        if (i == n - 1) a.push_back(maxneg);
      }
    }
    long long ans = 0;
    for (int i = 0; i < a.size(); i++) ans += a[i];
    cout << ans << endl;
  }
  return 0;
}
