#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    long long ar[n + 5], ne = 0, p = 0, sum = 0;
    for (int i = 1; i <= n; i++) cin >> ar[i];
    for (int i = 1; i <= n;) {
      long long a = 0, b = INT_MIN;
      if (ar[i] > 0) {
        while (ar[i] > 0) {
          a = max(a, ar[i]);
          i++;
          if (i > n) break;
        }
        sum += a;
        a = 0;
      }
      if (ar[i] < 0) {
        while (ar[i] < 0) {
          b = max(b, ar[i]);
          i++;
          if (i > n) break;
        }
        sum += b;
        b = INT_MIN;
      }
    }
    cout << sum << endl;
  }
}
