#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int t, n, x, mx, cnt, q;
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n + 1];
    cnt = 0;
    cin >> a[1];
    mx = a[1];
    for (int i = 2; i <= n; i++) {
      cin >> a[i];
      if (a[i - 1] > 0 && a[i] > 0)
        mx = max(a[i], mx);
      else if (a[i - 1] < 0 && a[i] < 0)
        mx = max(a[i], mx);
      else {
        cnt += mx;
        mx = a[i];
      }
    }
    cout << (long long int)cnt + mx << "\n";
  }
}
