#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int flag = 0;
    if (a[0] > 0)
      flag = 1;
    else
      flag = 0;
    long long mymax = a[0];
    long long sum = 0;
    for (int i = 1; i < n; i++) {
      if (flag == 1) {
        if (a[i] > 0) {
          if (mymax < a[i]) mymax = a[i];
        } else {
          flag = 0;
          sum += mymax;
          mymax = a[i];
        }
      } else {
        if (a[i] < 0) {
          if (mymax < a[i]) mymax = a[i];
        } else {
          flag = 1;
          sum += mymax;
          mymax = a[i];
        }
      }
    }
    cout << sum + mymax << endl;
  }
  return 0;
}
