#include <bits/stdc++.h>
using namespace std;
long long int a[200005];
int main() {
  long long int i, j, n, t, m, p_a, n_a, pos, neg, ck, sum;
  cin >> t;
  while (t--) {
    cin >> n;
    sum = 0, m = 0, p_a = -1000000000, n_a = -1000000000;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (i == 0) {
        if (a[i] >= 0) {
          pos = 1;
          p_a = a[i];
        } else {
          neg = 1;
          n_a = a[i];
        }
      } else if (neg == 1) {
        if (a[i] < 0) {
          n_a = max(n_a, a[i]);
        } else {
          sum = sum + n_a;
          n_a = -1000000000;
          neg = 0;
          pos = 1;
          p_a = max(p_a, a[i]);
        }
      } else {
        if (a[i] >= 0) {
          p_a = max(p_a, a[i]);
        } else {
          sum = sum + p_a;
          p_a = -1000000000;
          pos = 0;
          neg = 1;
          n_a = max(n_a, a[i]);
        }
      }
    }
    if (pos == 1) {
      sum = sum + p_a;
    } else if (neg == 1) {
      sum = sum + n_a;
    }
    cout << sum << endl;
  }
  return 0;
}
