Why this code not able to pass all test cases (149 , maximise sum)

#include<bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        vector<int> pos;
        vector<int> neg;
        long long sum = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if (a[i] < 0) {
                neg.push_back(abs(a[i]));
            } else {
                sum += a[i];
                pos.push_back(a[i]);
            }
        }

        sort(neg.begin(), neg.end());
        sort(pos.begin(), pos.end());
        if (neg.size() % 2 == 0) {
            for (auto it : neg) {
                sum += it;
            }
        } else {
            if (!pos.empty() && pos[0] < neg[0]) {
                sum -= pos[0];
                for (auto it : neg) {
                    sum += it;
                }
            } else {
                for (auto it : neg) {
                    sum += it;
                }
                sum -= 2LL * neg[0];
            }
        }
        cout << sum << "\n";
    }
    return 0;
}