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