#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, i, ans = 0, p = 0, q = -10000000000;
    cin >> n;
    long long a[n];
    i = 1;
    cin >> a[0];
    if (a[0] > 0) {
      p = a[0];
    } else {
      q = a[0];
    }
    while (i < n) {
      cin >> a[i];
      if (a[i] > 0) {
        if (a[i - 1] < 0) {
          ans += q;
          q = -10000000000;
        }
        p = max(p, a[i]);
      } else {
        if (a[i - 1] > 0) {
          ans += p;
          p = 0;
        }
        q = max(q, a[i]);
      }
      i++;
    }
    if (p != 0) {
      ans += p;
    }
    if (q != -10000000000) {
      ans += q;
    }
    cout << ans << '\n';
  }
}
