description: You are given a permutation p consisting of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once).
  
  Let's call an array a bipartite if the following undirected graph is bipartite:
  
    * the graph consists of n vertices; 
    * two vertices i and j are connected by an edge if i < j and a_i > a_j. 
  
  
  
  Your task is to find a bipartite array of integers a of size n, such that a_i = p_i or a_i = -p_i, or report that no such array exists. If there are multiple answers, print any of them.
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 2 ⋅ 10^5) — the number of test cases.
  
  The first line of each test case contains a single integer n (1 ≤ n ≤ 10^6) — the size of the permutation.
  
  The second line contains n integers p_1, p_2, ..., p_n.
  
  The sum of n over all test cases doesn't exceed 10^6.
  
  Output
  
  For each test case, print the answer in the following format. If such an array a does not exist, print "NO" in a single line. Otherwise, print "YES" in the first line and n integers — array a in the second line.
  
  Example
  
  Input
  
  
  4
  3
  1 2 3
  6
  1 3 2 6 5 4
  4
  4 1 3 2
  8
  3 2 1 6 7 8 5 4
  
  
  Output
  
  
  YES
  1 2 3
  NO
  YES
  -4 -1 -3 -2
  YES
  -3 -2 1 6 7 -8 -5 -4
solution: #include <bits/stdc++.h>
  using namespace std;
  bool sgn[4][1000000];
  int prv[4][1000000];
  int p[1000000];
  pair<int, int> put(pair<int, int> pr, int x) {
    if (pr.first <= x) return make_pair(x, pr.second);
    if (pr.second <= x) return make_pair(pr.first, x);
    return make_pair(INT32_MAX, INT32_MAX);
  }
  void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> p[i];
    }
    vector<pair<int, int> > ps, ps_tmp;
    ps.emplace_back(INT32_MIN, INT32_MIN);
    for (int i = 0; i < n; i++) {
      int pidx = 0;
      for (auto& pr : ps) {
        pair<int, int> rp = put(pr, p[i]);
        if (rp.first != INT32_MAX) {
          bool ok = false;
          int j = 0;
          for (auto& pt : ps_tmp) {
            if (pt.first >= rp.first && pt.second >= rp.second) {
              pt = rp;
              ok = true;
              prv[j][i] = pidx;
              sgn[j][i] = true;
              break;
            }
            if (pt.first <= rp.first && pt.second <= rp.second) {
              ok = true;
              break;
            }
            j++;
            assert(j < 4);
          }
          if (!ok) {
            prv[j][i] = pidx;
            sgn[j][i] = true;
            ps_tmp.push_back(rp);
          }
        }
        rp = put(pr, -p[i]);
        if (rp.first != INT32_MAX) {
          bool ok = false;
          int j = 0;
          for (auto& pt : ps_tmp) {
            if (pt.first >= rp.first && pt.second >= rp.second) {
              pt = rp;
              ok = true;
              prv[j][i] = pidx;
              sgn[j][i] = false;
              break;
            }
            if (pt.first <= rp.first && pt.second <= rp.second) {
              ok = true;
              break;
            }
            j++;
            assert(j < 4);
          }
          if (!ok) {
            prv[j][i] = pidx;
            sgn[j][i] = false;
            ps_tmp.push_back(rp);
          }
        }
        pidx++;
      }
      swap(ps, ps_tmp);
      ps_tmp.clear();
      if (ps.empty()) {
        cout << "NO\n";
        return;
      }
    }
    int j = 0;
    int i = n - 1;
    while (i >= 0) {
      if (!sgn[j][i]) p[i] = -p[i];
      j = prv[j][i];
      i--;
    }
    cout << "YES\n";
    for (i = 0; i < n; i++) {
      cout << p[i] << " ";
    }
    cout << "\n";
  }
  int main() {
    ios::sync_with_stdio(false);
    int ncases;
    cin >> ncases;
    for (int i = 1; i <= ncases; i++) {
      solve();
    }
    cout.flush();
    return 0;
  }
  