#include <bits/stdc++.h>
using namespace std;
int num[200010];
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    long long sum = 0, maxn = -1e18;
    bool pos;
    cin >> n;
    cin >> num[1];
    sum += num[1];
    pos = num[1] > 0 ? true : false;
    int cnt = 1, lenmax = 1;
    for (int i = 2; i <= n; i++) {
      cin >> num[i];
      if ((num[i] > 0 && !pos) || (num[i] < 0 && pos)) {
        cnt++;
        sum += num[i];
        pos = num[i] > 0 ? true : false;
      } else {
        if (cnt >= lenmax) {
          if (maxn < sum) maxn = sum;
          pos = num[i] > 0 ? true : false;
          lenmax = cnt;
          cnt = 1;
          sum = num[i];
        } else {
          cnt = 1;
          sum = num[i];
        }
      }
    }
    if (cnt >= lenmax)
      if (maxn < sum) maxn = sum;
    cout << maxn << endl;
  }
  return 0;
}
