#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 20;
const int inf = 1e9 + 10;
long long a[N];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    int cnt1 = 0, cnt2 = 0;
    long long max1 = -inf;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] < 0)
        cnt1++;
      else
        cnt2++;
      max1 = max(max1, a[i]);
    }
    if (cnt1 == n || cnt2 == n) {
      cout << max1 << endl;
      continue;
    }
    long long sum = 0;
    for (int i = 0; i < n;) {
      bool flag = 0;
      max1 = -inf;
      while (a[i] > 0 && i < n) flag = 1, max1 = max(max1, a[i]), i++;
      if (flag) sum += max1;
      flag = 0, max1 = -inf;
      while (a[i] < 0 && i < n) flag = 1, max1 = max(max1, a[i]), i++;
      if (flag) sum += max1;
    }
    cout << sum << endl;
  }
  return 0;
}
