#include <bits/stdc++.h>
using namespace std;
const long long MM = 8ll * 1000000007 * 1000000007;
int n, a[2000005];
void Solve() {
  int test;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int i = 1;
    long long sum = 0;
    while (i <= n) {
      int maxx = -1e9;
      if (a[i] < 0) {
        while (a[i] < 0 && i <= n) {
          maxx = max(maxx, a[i]);
          i++;
        }
        sum += maxx;
      } else {
        while (a[i] > 0 && i <= n) {
          maxx = max(maxx, a[i]);
          i++;
        }
        sum += maxx;
      }
    }
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Solve();
}
