// codeforces/629div3/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int _;
  cin >> _;

  int n;
  while (cin >> n) {
    vec<int> v(n);
    cin >> v;

    vec<pair<int, int>> u;
    each (i, v) {
      if (u.empty()) {
        u.push_back(make_pair(i, 1));
      } else {
        if (u.back().first == i) {
          ++u.back().second;
        } else {
          u.push_back(make_pair(i, 1));
        }
      }
    }

    vec<pair<int, int>> w = u;
    for (int i = 0; i < u.size(); ++i) {
      w[i].first = i % 2;
    }

    if (w.front().first == w.back().first && v.front() != v.back()) {
      w.back().first = 2;
    }

    cout << w.back().first + 1 << endl;
    each (i, w) {
      for (int j = 0; j < i.second; ++j) {
        cout << i.first + 1 << ' ';
      }
    }
    cout << endl;
  }

  return 0;
}


// codeforces/629div3/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int _;
  cin >> _;

  int n;
  while (cin >> n) {
    vec<int> v(n);
    cin >> v;

    map<int, int> m;
    int c = 0;
    v[v[0]] = c;
    for (int i = 1; i < v.size(); ++i) {
      if (v[i - 1] != v[i]) {
        c = (c + 1) % 2;
      }
      m[v[i]] = c;
    }

    int x = 2;
    if (m[v.front()] == m[v.back()] && v.front() != v.back()) {
      ++x;
    }

    cout << x << endl;
    each (i, v) cout << m[i] + 1 << ' '; cout << endl;
  }

  return 0;
}


// codeforces/629div3/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int _;
  cin >> _;

  int n;
  while (cin >> n) {
    vec<int> v(n);
    cin >> v;

    map<int, int> m;
    int c = 0;
    m[v[0]] = c;
    for (int i = 1; i < v.size(); ++i) {
      if (v[i - 1] != v[i]) {
        c = (c + 1) % 2;
      }
      m[v[i]] = c;
    }

    if (m[v.front()] == m[v.back()] && v.front() != v.back()) {
      m[v.back()] = 2;
    }

    set<int> vis;
    each (i, v) vis.insert(m[i]);
    cout << vis.size() << endl;
    each (i, v) cout << m[i] + 1 << ' '; cout << endl;
  }

  return 0;
}


// codeforces/629div3/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int _;
  cin >> _;

  int n;
  while (cin >> n) {
    vec<int> v(n);
    cin >> v;

    {
      set<int> vis;
      each (i, v) vis.insert(i);
      if (vis.size() == 1) {
        cout << 1 << endl;
        for (int i = 0; i < n; ++i) {
          cout << 1 << ' ';
        }
        cout << endl;
        continue;
      }
    }

    vec<int> u;
    for (int i = 0; i < v.size(); ++i) {
      u.push_back(i % 2);
    }

    if (u.back() == u.front() && v.back() != v.front()) {
      bool f = false;
      for (int i = 0; i + 1 < v.size(); ++i) {
        if (f) {
          u[i] = (i + 1) % 2;
        }
        f = f || (v[i] == v[i + 1]);
      }
      if (!f) u.back() = 2;
    }
    set<int> vis;
    each (i, u) vis.insert(i);
    cout << vis.size() << endl;
    each (i, u) cout << i+1 << ' '; cout << endl;
  }

  return 0;
}


// codeforces/629div3/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int _;
  cin >> _;

  int n;
  while (cin >> n) {
    vec<int> v(n);
    cin >> v;

    vec<int> u;
    map<int, int> m;
    each (i, v) {
      if (m.count(i) == 0) {
        m[i] = m.size();
      }
      u.push_back(m[i] + 1);
    }
    cout << m.size() << endl;
    each (i, u) cout << i << ' '; cout << endl;
  }

  return 0;
}


// codeforces/629div3/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int _;
  cin >> _;

  int n;
  while (cin >> n) {
    vec<int> v(n);
    cin >> v;

    vec<int> u;
    for (int i = 0; i < v.size(); ++i) {
      u.push_back(i % 2);
    }

    if (u.back() == u.front() && v.back() != v.front()) {
      bool f = false;
      for (int i = 0; i + 1 < v.size(); ++i) {
        if (f) {
          u[i] = (i + 1) % 2;
        }
        f = f || (v[i] == v[i + 1]);
      }
      if (!f) u.back() = 2;
    }
    set<int> vis;
    each (i, u) vis.insert(i);
    cout << vis.size() << endl;
    each (i, u) cout << i+1 << ' '; cout << endl;
  }

  return 0;
}


// codeforces/629div3/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int _;
  cin >> _;

  int n;
  while (cin >> n) {
    vec<int> v(n);
    cin >> v;

    bool f = true;
    each (i, v) f = f && (v.front() == i);

    if (f) {
      cout << 1 << endl;
      each (i, v) cout << 1 << ' ' ; cout << endl;
      continue;
    }

    vec<int> u;
    for (int i = 0; i < n; ++i) {
      u.push_back(i % 2);
    }

    if (u.back() == u.front() && v.front() != v.back()) {
      int k = -1;
      for (int i = 0; i + 1 < v.size(); ++i) {
        if (v[i] == v[i + 1]) {
          k = i + 1;
          break;
        }
      }
      if (k == -1) {
        u.back() = 2;
      } else {
        for (int i = k; i < n; ++i) {
          u[i] = (i + 1) % 2;
        }
      }
    }

    set<int> vis;
    each (i, u) vis.insert(i);
    cout << vis.size() << endl;
    each (i, u) cout << i+1 << ' '; cout << endl;
  }

  return 0;
}


// codeforces/629div3/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int _;
  cin >> _;

  int n;
  while (cin >> n) {
    vec<int> v(n);
    cin >> v;

    {
      set<int> vis;
      each (i, v) vis.insert(i);
      if (vis.size() == 1) {
        cout << 1 << endl;
        for (int i = 0; i < n; ++i) {
          cout << 1 << ' ';
          cout << endl;
        }
        continue;
      }
    }

    vec<int> u;
    for (int i = 0; i < v.size(); ++i) {
      u.push_back(i % 2);
    }

    if (u.back() == u.front() && v.back() != v.front()) {
      bool f = false;
      for (int i = 0; i + 1 < v.size(); ++i) {
        if (f) {
          u[i] = (i + 1) % 2;
        }
        f = f || (v[i] == v[i + 1]);
      }
      if (!f) u.back() = 2;
    }
    set<int> vis;
    each (i, u) vis.insert(i);
    cout << vis.size() << endl;
    each (i, u) cout << i+1 << ' '; cout << endl;
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int t,n;
    cin>>t;
   while(--t){
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    if(count(a.begin(),a.end(),a[0])==n){
        cout<<"1"<<endl;
        for(int i=0;i<n;++i){
            cout<<"1 ";
        }

    }
    else if(n%2==0){
        cout<<"2"<<endl;
        for(int i=0, p=0;p<n;++p,i^=1){
            cout<<1+i<<" ";
        }

    }
    else {int o=0;
            for(int i=0;i<n;++i){
                if(a[i]==a[i+1]){
                    ++o;
                    }
            }
            if(o==0){
                cout<<"3"<<endl;
                cout<<"3 ";
            }
            else {cout<<"2"<<endl;cout<<"2 ";}
        for(int i=0, j=0;i<n-1;++i,j^=1){
            cout<<1+j<<" " ;
        }

    }
    cout<<endl;
   }
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);

    int t;
    cin >> t;
        string n;
        string ans = "";

    for (int i = 0; i < t; i++) {
        cin >> n;
        vector<char> even (n.size());
        vector<char> odd (n.size());
        int el = 0;
        int ol = 0;
        for (int i = 0; i < n.size(); i++) {
            if ((n[i] - '0')%2) {
                odd[ol] = n[i];
                ol++;
            } else {
                even[el] = n[i];
                el++;
            }
        }
        ans = "";
        int oi = 0;
        int ei = 0;
        while (oi < ol && ei < el) {
            if (even[ei] < odd[oi]) {
                ans = ans + even[ei];
                ei++;
            } else {
                ans = ans + odd[oi];
                oi++;
            }
        }

        while (ei < el) {
            ans = ans + even[ei];
            ei++;
        }
        while (oi < ol) {
            ans = ans + odd[oi];
            oi++;
        }
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);

    int t;
    cin >> t;
        string n;
        string ans = "";

    while (t--) {
        cin >> n;
        vector<char> even;
        vector<char> odd;
        int el = 0;
        int ol = 0;
        for (int i = 0; i < n.size(); i++) {
            if ((n[i] - '0')%2) {
                odd.push_back(n[i]);
            } else {
                even.push_back(n[i]);
            }
        }
        ans = "";
        int oi = 0;
        int ei = 0;
        while (oi < odd.size() && ei < even.size()) {
            if (even[ei] < odd[oi]) {
                ans = ans + even[ei];
                ei++;
            } else {
                ans = ans + odd[oi];
                oi++;
            }
        }

        while (ei < even.size()) {
            ans = ans + even[ei];
            ei++;
        }
        while (oi < odd.size()) {
            ans = ans + odd[oi];
            oi++;
        }
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        string n;
        cin >> n;
        queue<char> even;
        queue<char> odd;
        for (int i = 0; i < n.size(); i++) {
            if ((n[i] - '0')%2) {
                odd.push(n[i]);
            } else {
                even.push(n[i]);
            }
        }
        string ans = "";
        while (!even.empty() && !odd.empty()) {
            if (even.front() < odd.front()) {
                ans = ans + even.front();
                even.pop();
            } else {
                ans = ans + odd.front();
                odd.pop();
            }
        }

        while (!even.empty()) {
            ans = ans + even.front();
            even.pop();
        }
        while (!odd.empty()) {
            ans = ans + odd.front();
            odd.pop();
        }
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

void rec (stack<char> &even, stack<char> &odd, string &n){
    if (n.size() == 0) return;
    char r = n[n.size()-1];
    if ((r - '0')%2) {
        odd.push(r);
    } else {
        even.push(r);
    }

    n = n.substr(0, n.size()-1);
    rec(even, odd, n);
}

int main() {

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        string n;
        cin >> n;
        int zeroes = 0;
        for (int i = 0; i < n.size(); i++) {
            if(n[i] == '0') {
                zeroes++;
                n = n.substr(0, i) + n.substr(i+1);
            }
        }
        stack<char> even;
        stack<char> odd;
        rec (even, odd, n);
        string ans = "";
        while (!even.empty() && even.top() == 0) {
            zeroes++;
            even.pop();
        }
        while (!even.empty() && !odd.empty()) {
            if (even.top() < odd.top()) {
                ans = ans + even.top();
                even.pop();
            } else {
                ans = ans + odd.top();
                odd.pop();
            }
        }

        while (!even.empty()) {
            ans = ans + even.top();
            even.pop();
        }
        while (!odd.empty()) {
            ans = ans + odd.top();
            odd.pop();
        }
        //cout << zeroes << endl;
        for (int i = 0; i < zeroes; i++) cout << 0;
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

void rec (stack<char> &even, stack<char> &odd, string &n){
    if (n.size() == 0) return;
    char r = n[n.size()-1];
    if ((r - '0')%2) {
        odd.push(r);
    } else {
        even.push(r);
    }

    n = n.substr(0, n.size()-1);
    rec(even, odd, n);
}

int main() {

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        string n;
        cin >> n;
        /*
        int zeroes = 0;
        for (int i = 0; i < n.size(); i++) {
            if(n[i] == '0') {
                zeroes++;
                n = n.substr(0, i) + n.substr(i+1);
            }
        }
        */
        stack<char> even;
        stack<char> odd;
        rec (even, odd, n);
        string ans = "";
        /*
        while (!even.empty() && even.top() == 0) {
            zeroes++;
            even.pop();
        }
        */
        while (!even.empty() && !odd.empty()) {
            if (even.top() < odd.top()) {
                ans = ans + even.top();
                even.pop();
            } else {
                ans = ans + odd.top();
                odd.pop();
            }
        }

        while (!even.empty()) {
            ans = ans + even.top();
            even.pop();
        }
        while (!odd.empty()) {
            ans = ans + odd.top();
            odd.pop();
        }
        //cout << zeroes << endl;
        //for (int i = 0; i < zeroes; i++) cout << 0;
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

void rec (stack<int> &even, stack<int> &odd, int n){
    if (n == 0) return;
    int r = n%10;
    if (r%2) {
        odd.push(r);
    } else {
        even.push(r);
    }

    n = n/10;
    rec(even, odd, n);
}

int main() {

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        int n;
        cin >> n;
        stack<int> even;
        stack<int> odd;
        rec (even, odd, n);
        int ans = 0;
        while (!even.empty() && !odd.empty()) {
            if (even.top() < odd.top()) {
                ans = ans*10 + even.top();
                even.pop();
            } else {
                ans = ans*10 + odd.top();
                odd.pop();
            }
        }

        while (!even.empty()) {
            ans = ans*10 + even.top();
            even.pop();
        }
        while (!odd.empty()) {
            ans = ans*10 + odd.top();
            odd.pop();
        }

        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);

    int t;
    cin >> t;
        string n;
        string ans = "";

    for (int i = 0; i < t; i++) {
        cin >> n;
        vector<char> even (300000);
        vector<char> odd (300000);
        int el = 0;
        int ol = 0;
        for (int i = 0; i < n.size(); i++) {
            if ((n[i] - '0')%2) {
                odd[ol] = n[i];
                ol++;
            } else {
                even[el] = n[i];
                el++;
            }
        }
        ans = "";
        int oi = 0;
        int ei = 0;
        while (oi < ol && ei < el) {
            if (even[ei] < odd[oi]) {
                ans = ans + even[ei];
                ei++;
            } else {
                ans = ans + odd[oi];
                oi++;
            }
        }

        while (ei < el) {
            ans = ans + even[ei];
            ei++;
        }
        while (oi < ol) {
            ans = ans + odd[oi];
            oi++;
        }
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);

    int t;
    cin >> t;
        string n;
        string ans = "";

    for (int i = 0; i < t; i++) {
        cin >> n;
        vector<char> even;
        vector<char> odd;
        int el = 0;
        int ol = 0;
        for (int i = 0; i < n.size(); i++) {
            if ((n[i] - '0')%2) {
                odd.push_back(n[i]);
            } else {
                even.push_back(n[i]);
            }
        }
        ans = "";
        int oi = 0;
        int ei = 0;
        while (oi < odd.size() && ei < even.size()) {
            if (even[ei] < odd[oi]) {
                ans = ans + even[ei];
                ei++;
            } else {
                ans = ans + odd[oi];
                oi++;
            }
        }

        while (ei < even.size()) {
            ans = ans + even[ei];
            ei++;
        }
        while (oi < odd.size()) {
            ans = ans + odd[oi];
            oi++;
        }
        cout << ans << endl;
    }

    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(long long i=0;i<n;i++)
#define sp <<" "<<
#define ll long long int
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
#define tin 1000000000
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
int main()
{
    ios
	ll j,i,n,l,c,h,k,da,m,maxi,d;
	cin>>n;
	string s;
	string w="",y="",x="";
	for(i=0;i<n;i++)
	{
		cin>>s;
		w="";y="";x="";
		for(j=0;j<s.length();j++)
		{
			if(((s[j]))%2==0)
			{
				w=w+s[j];
			}
			else
				y=y+s[j];

		}
		c=0;d=0;
		if(c==w.length())
			{

				x=x+y.substr(d);
				goto p;
			}
			if(d==y.length())
			{
				x=x+w.substr(c);
				goto p;
			}
		while(x.length()!=s.length())
		{
			if(int(w[c])<int(y[d]))
			{
				x=x+w[c];
				c++;
			}
			else
			{
				x=x+y[d];
				d++;
			}
			if(c==w.length())
			{
				x=x+y.substr(d);
				break;
			}
			if(d==y.length())
			{
				x=x+w.substr(c);
				break;
			}

		}
		p: cout<<x<<endl;
	}
}


#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(long long i=0;i<n;i++)
#define sp <<" "<<
#define ll long long int
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
#define tin 1000000000
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
int main()
{
    ios
	int j,i,n,l,c,h,k,da,m,maxi,d,t;
	    cin>>t;
    while(t--){
        string s;cin>>s;
        string a="",b="";
        for(char ch : s){
            if((ch-'0')%2 == 1){b+=ch;}
            else a+=ch;
        }
        s="";
        int i=0;int j=0;
        int al=a.length();int bl = b.length();
        while(true){
            if(i>=al){
                while(j<bl){
                    s+=b[j];j++;
                }
                break;
            }
            if(j>=bl){
                while(i<al){
                    s+=a[i];i++;
                }
                break;
            }
            if(a[i]<b[j]){s+=a[i];i++;}
            else s+=b[j],j++;
        }
        cout<<s<<endl;
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(long long i=0;i<n;i++)
#define sp <<" "<<
#define ll long long int
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
#define tin 1000000000
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
int main()
{
    ios
	ll j,i,n,l,c,h,k,da,m,maxi,d;
	cin>>n;
	string w="",y="",x="",a,s;
	for(i=0;i<n;i++)
	{
	    cin>>s;
		w="";y="";x="";
		for(j=0;j<s.length();j++)
		{
			if(((s[j]))%2==0)
			{
				w=w+s[j];
			}
			else
				y=y+s[j];

		}
		c=0;d=0;
		l=w.length();
		h=y.length();
		while(c<l || d<h)
		{
			if(c==l)
			{
				cout<<y[d];
				d++;
			}
			else if(d==h)
			{
				cout<<w[c];
				c++;
			}
			else if((w[c])<(y[d]))
			{
				cout<<w[c];
				c++;
			}
			else
			{
				cout<<y[d];
				d++;
			}

		}
		cout<<endl;
	}
}


#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(long long i=0;i<n;i++)
#define sp <<" "<<
#define ll long long int
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
#define tin 1000000000
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
int main()
{
    ios
	ll j,i,n,l,c,h,k,da,m,maxi,d,t;
	    cin>>t;
    while(t--){
        string s;cin>>s;
        string a="",b="";
        for(char ch : s){
            if((ch-'0')%2 == 1){b+=ch;}
            else a+=ch;
        }
        s="";
        int i=0;int j=0;
        int al=a.length();int bl = b.length();
        while(true){
            if(i>=al){
                while(j<bl){
                    s+=b[j];j++;
                }
                break;
            }
            if(j>=bl){
                while(i<al){
                    s+=a[i];i++;
                }
                break;
            }
            if(a[i]<b[j]){s+=a[i];i++;}
            else s+=b[j],j++;
        }
        cout<<s<<endl;
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(long long i=0;i<n;i++)
#define sp <<" "<<
#define ll long long int
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
#define tin 1000000000
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
int main()
{
    ios
	ll j,i,n,l,c,h,k,da,m,maxi,d;
	cin>>n;
	string w="",y="",x="",a,s;
	for(i=0;i<n;i++)
	{
	    cin>>s;
		w="";y="";x="";
		for(j=0;j<s.length();j++)
		{
			if(((s[j]))%2==0)
			{
				w=w+s[j];
			}
			else
				y=y+s[j];

		}
		c=0;d=0;
		l=w.lenth();
		h=y.length();
		while(c<l || d<h)
		{
			if(c==l)
			{
				cout<<y[d];
				d++;
			}
			else if(d==h)
			{
				cout<<w[c];
				c++;
			}
			else if((w[c])<(y[d]))
			{
				cout<<w[c];
				c++;
			}
			else
			{
				cout<<y[d];
				d++;
			}

		}
	}
}


#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(long long i=0;i<n;i++)
#define sp <<" "<<
#define ll long long int
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
#define tin 1000000000
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
int main()
{
    ios
	int j,i,n,l,c,h,k,da,m,maxi,d;
	cin>>n;
	string w="",y="",x="",a,s;
	for(i=0;i<n;i++)
	{
	    cin>>s;
	    l=s.length();
	    int a[l];
		w="";y="";x="";
		for(j=0;j<s.length();j++)
		{
			a[j]=s[j]-'0';
			if(((a[j]))%2==0)
			{
				w=w+s[j];
			}
			else
				y=y+s[j];

		}
		c=0;d=0;
		l=w.length();
		h=y.length();
		while(c<l || d<h)
		{
			if(c==l)
			{
				cout<<y[d];
				d++;
			}
			else if(d==h)
			{
				cout<<w[c];
				c++;
			}
			else if((w[c])<(y[d]))
			{
				cout<<w[c];
				c++;
			}
			else
			{
				cout<<y[d];
				d++;
			}

		}
		cout<<endl;
	}
}


#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(long long i=0;i<n;i++)
#define sp <<" "<<
#define ll long long int
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
#define tin 1000000000
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
int main()
{
    ios
	ll j,i,n,l,c,h,k,da,m,maxi,d;
	cin>>n;
	string w="",y="",x="",a,s;
	for(i=0;i<n;i++)
	{
	    cin>>s;
		w="";y="";x="";
		for(j=0;j<s.length();j++)
		{
			if(((s[j]))%2==0)
			{
				w=w+s[j];
			}
			else
				y=y+s[j];

		}
		c=0;d=0;
		while(c<w.length() || d<y.length())
		{
			if(c==w.length())
			{
				cout<<y[d];
				d++;
			}
			else if(d==y.length())
			{
				cout<<w[c];
				c++;
			}
			else if((w[c])<(y[d]))
			{
				cout<<w[c];
				c++;
			}
			else
			{
				cout<<y[d];
				d++;
			}

		}
		cout<<endl;
	}
}


#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(long long i=0;i<n;i++)
#define sp <<" "<<
#define ll long long int
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
#define tin 1000000000
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
int main()
{
    ios
	ll j,i,n,l,c,h,k,da,m,maxi,d;
	cin>>n;
	string s;
	char t;
	for(i=0;i<n;i++)
	{
		cin>>s;
		string w="",y="",x="";
		for(j=0;j<s.length();j++)
		{
			if(((s[j])-'0')%2==0)
			{
				w=w+s[j];
			}
			else
				y=y+s[j];

		}
		c=0;d=0;
		if(c==w.length())
			{

				x=x+y.substr(d);
				goto p;
			}
			if(d==y.length())
			{
				x=x+w.substr(c);
				goto p;
			}
		while(x.length()!=s.length())
		{
			if(int(w[c])<int(y[d]))
			{
				x=x+w[c];
				c++;
			}
			else
			{
				x=x+y[d];
				d++;
			}
			if(c==w.length())
			{
				x=x+y.substr(d);
				break;
			}
			if(d==y.length())
			{
				x=x+w.substr(c);
				break;
			}

		}
		p: cout<<x<<endl;
	}
}


#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(long long i=0;i<n;i++)
#define sp <<" "<<
#define ll long long int
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
#define tin 1000000000
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
int main()
{
    ios
	ll j,i,n,l,c,h,k,da,m,maxi,d;
	cin>>n;
	string s;
	char t;
	for(i=0;i<n;i++)
	{
		cin>>s;
		string w="",y="",x="";
		for(j=0;j<s.length();j++)
		{
			if((int(s[j]))%2==0)
			{
				w=w+s[j];
			}
			else
				y=y+s[j];

		}
		c=0;d=0;
		if(c==w.length())
			{
				x=x+y.substr(d);
				goto p;
			}
			if(d==y.length())
			{
				x=x+w.substr(c);
				goto p;
			}
		while(x.length()!=s.length())
		{
			if(int(w[c])<int(y[d]))
			{
				x=x+w[c];
				c++;
			}
			else
			{
				x=x+y[d];
				d++;
			}
			if(c==w.length())
			{
				x=x+y.substr(d);
				break;
			}
			if(d==y.length())
			{
				x=x+w.substr(c);
				break;
			}

		}
		p: cout<<x<<endl;
	}
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	cin >> t;
	while (t--) {
		string a;
		cin >> a;
		int sza = a.size();

		int beg = 0;
		for (int i = 0; i < sza; i++) {
			while (i < sza && a[i] % 2 == a[beg] % 2)
				i++;
			if (i == sza)
				break;

			if (a[i] < a[beg]) {
//				cout << beg << " " << i << "\n";
				int tmp = a[i];
				a.erase(a.begin() + i);
				a.insert(a.begin() + beg, tmp);
				beg++;
			} else {
				while (beg < i && a[i] >= a[beg])
					beg++;
//				cout << beg << " " << i << "\n";
				if (beg != i) {
					int tmp = a[i];
					a.erase(a.begin() + i);
					a.insert(a.begin() + beg, tmp);
					beg++;
				}
			}
		}

		cout << a << "\n";
	}
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	cin >> t;
	while (t--) {
		string a,s;
		cin >> s;
		int szs = s.size();

		int beg = 0;
		for (int i = 0; i < szs; i++) {

			a.push_back(s[i]);
			while (i < szs && a[i] % 2 == a[beg] % 2){
				i++;
				if(i<szs)a.push_back(s[i]);
			}
			if (i == szs)
				break;

			if (a[i] < a[beg]) {
				int tmp = a[i];
				a.erase(a.begin() + i);
				a.insert(a.begin() + beg, tmp);
				beg++;
			} else {
				while (beg < i && a[i] >= a[beg])
					beg++;
				if (beg != i) {
					int tmp = a[i];
					a.erase(a.begin() + i);
					a.insert(a.begin() + beg, tmp);
					beg++;
				}
			}
		}

		cout << a << "\n";
	}
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	cin >> t;
	while (t--) {
		string a;
		cin >> a;
		int sza = a.size();

		int beg = 0;
		for (int i = 0; i < sza; i++) {
			while (i < sza && a[i] % 2 == a[beg] % 2)
				i++;
			if (i == sza)
				break;

			if (a[i] < a[beg]) {
//				cout << beg << " " << i << "\n";
				int tmp = a[i];
				a[i] = a[beg];
				a[beg] = tmp;
				beg++;
			} else {
				while (beg < i && a[i] >= a[beg])
					beg++;
//				cout << beg << " " << i << "\n";
				if (beg != i) {
					int tmp = a[i];
					a[i] = a[beg];
					a[beg] = tmp;
					beg++;
				}
			}
		}

		cout << a << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int t;
string a;

int main() {
	cin >> t;
	for(int tc = 0; tc < t; ++tc){
		cin >> a;
		string s[2];
		for(auto x : a)
			s[int(x - '0') & 1] += x;

		reverse(s[0].begin(), s[0].end());
		reverse(s[1].begin(), s[1].end());

		string res = "";
		while(!(s[0].empty() && s[1].empty())){
			if(s[0].empty()){
				res += s[1].back();
				s[1].pop_back();
				continue;
			}
			if(s[1].empty()){
				res += s[0].back();
				s[0].pop_back();
				continue;
			}

			if(s[0].back() < s[1].back()){
				res += s[0].back();
				s[0].pop_back();
			}
			else{
				res += s[1].back();
				s[1].pop_back();
			}
		}

		cout << res << endl;
	}
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	cin >> t;
	while (t--) {
		string a,s;
		cin >> s;
		int szs = s.size();

		int beg = 0;
		for (int i = 0; i < szs; i++) {

			a.push_back(s[i]);
			while (i < szs && a[i] % 2 == a[beg] % 2){
				i++;
				a.push_back(s[i]);
			}
			if (i == szs)
				break;

			if (a[i] < a[beg]) {
//				cout << beg << " " << i << "\n";
				int tmp = a[i];
				a.erase(a.begin() + i);
				a.insert(a.begin() + beg, tmp);
				beg++;
			} else {
				while (beg < i && a[i] >= a[beg])
					beg++;
//				cout << beg << " " << i << "\n";
				if (beg != i) {
					int tmp = a[i];
					a.erase(a.begin() + i);
					a.insert(a.begin() + beg, tmp);
					beg++;
				}
			}
		}

		cout << a << "\n";
	}
}


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

int main() {
	int t;
	cin >> t;
	while (t--) {
		string a;
		cin >> a;
		int sza = a.size();

		int beg = 0;
		for (int i = 0; i < sza; i++) {
			while (i < sza && a[i] % 2 == a[beg] % 2)
				i++;
			if (i == sza)
				break;

			if (a[i] < a[beg]) {
//				cout << beg << " " << i << "\n";
				int tmp = a[i];
				a.erase(a.begin() + i);
				a.insert(a.begin() + beg, tmp);
				beg++;
			} else {
				while (beg < i && a[i] >= a[beg])
					beg++;
//				cout << beg << " " << i << "\n";
				if (beg != i) {
					int tmp = a[i];
					a.erase(a.begin() + i);
					a.insert(a.begin() + beg, tmp);
					beg++;
				}
			}
		}

		cout << a << "\n";
	}
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	cin >> t;
	while (t--) {
		string a,s;
		cin >> s;
		int szs = s.size();

		int beg = 0;
		for (int i = 0; i < szs; i++) {

			a.push_back(s[i]);
			while (i < szs && a[i] % 2 == a[beg] % 2){
				i++;
				if(i<szs)a.push_back(s[i]);
			}
			if (i == szs)
				break;

			if (a[i] < a[beg]) {
//				cout << beg << " " << i << "\n";
				int tmp = a[i];
				a.erase(a.begin() + i);
				a.insert(a.begin() + beg, tmp);
				beg++;
			} else {
				while (beg < i && a[i] >= a[beg])
					beg++;
//				cout << beg << " " << i << "\n";
				if (beg != i) {
					int tmp = a[i];
					a.erase(a.begin() + i);
					a.insert(a.begin() + beg, tmp);
					beg++;
				}
			}
		}

		cout << a << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int q;
    cin >> q;
    for(int k=0; k<q; k++){
        string s;
        cin >> s;
        int n = (int)(s.size());
        bool change = true;
        while(change){
            change = false;
            int r = (s[0] - '0')%2;
            vector< pair<char , int> > v;
            set<char> c;
            v.push_back({s[0], 0});
            c.insert(s[0]);
            for(int i=1; i<n; i++){
                if((s[i] - '0')%2 == r){
                    if(c.count(s[i]) == 0){
                        c.insert(s[i]);
                        v.push_back({s[i], i});
                    }
                }else{
                    auto it = c.end();
                    it--;
                    if(s[i] < *it){
                        int m = i;
                        for(auto x : v){
                            if(s[i]  < x.first) m = min(m, x.second);
                        }
                        int M = 0;
                        while(i + M < n && (s[i + M] - '0')%2 != r && s[i + M] < s[m]) M++;
                        char am[i - m];
                        char ai[M];
                        for(int j=0; j<M; j++){
                            ai[j] = s[i+j];
                        }
                        for(int j = 0; j < i - m; j++){
                            am[j] = s[m + j];
                        }
                        for(int j=0; j<M; j++){
                            s[j + m] = ai[j];
                        }
                        for(int j=0; j < i - m; j++){
                            s[m + M + j] = am[j];
                        }
                        i += M-1;
                        change = true;
                    }
                    c.clear();
                    v.clear();
                    v.push_back({s[i],i});
                    c.insert(s[i]);
                    r = (s[i] - '0')%2;

                }
            }
        }
        cout << s << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        string s;
        cin >> s;
        int n = (int) s.size(), left = 0, right = 0, r;
        vector<char> first;
        queue<char> second;
        while(right < n){
            if(left == right){
                first.clear();
                r = (s[right] - '0')%2;
                while(right < n && (s[right] - '0')%2 == r){
                    first.push_back(s[right]);
                    right++;
                }
            }else if(s[left] < s[right]){
                while(left < right && s[left] < s[right]){
                    first.resize((int)first.size() - 1);
                    left++;
                }
            }else{
                while(right < n && (s[right] - '0')%2 != r && s[right] < s[left]){
                    second.push(s[right]);
                    right++;
                }
                while(!second.empty()){
                    s[left] = second.front();
                    second.pop();
                    left++;
                }
                int p = left;
                for(char x : first){
                    s[p] = x;
                    p++;
                }
                while(right < n && (s[right] - '0')%2 == r){
                    first.push_back(s[right]);
                    right++;
                }
            }
        }
        cout << s << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        string s;
        cin >> s;
        int n = (int) s.size(), left = 0, right = 0, r;
        vector<char> first;
        queue<char> second;
        while(right < n){
            if(left == right){
                first.clear();
                r = (s[right] - '0')%2;
                while(right < n && (s[right] - '0')%2 == r){
                    first.push_back(s[right]);
                    right++;
                }
            }else if(s[left] < s[right]){
                while(left < right && s[left] < s[right]){
                    first.erase(first.begin());
                    left++;
                }
            }else{
                while(right < n && (s[right] - '0')%2 != r && s[right] < s[left]){
                    second.push(s[right]);
                    right++;
                }
                while(!second.empty()){
                    s[left] = second.front();
                    second.pop();
                    left++;
                }
                int p = left;
                for(char x : first){
                    s[p] = x;
                    p++;
                }
                while(right < n && (s[right] - '0')%2 == r){
                    first.push_back(s[right]);
                    right++;
                }
            }
        }
        cout << s << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int q;
    cin >> q;
    for(int k=0; k<q; k++){
        string s;
        cin >> s;
        int n = (int)(s.size());
        int r = (s[0] - '0')%2;
        bool change = true;
        while(change){
            change = false;
            vector< pair<char , int> > v;
            set<char> c;
            v.push_back({s[0], 0});
            c.insert(s[0]);
            for(int i=1; i<n; i++){
                if((s[i] - '0')%2 == r){
                    if(c.count(s[i]) == 0){
                        c.insert(s[i]);
                        v.push_back({s[i], i});
                    }
                }else{
                    auto it = c.end();
                    it--;
                    if(s[i] < *it){
                        int m = i;
                        for(auto x : v){
                            if(s[i]  < x.first) m = min(m, x.second);
                        }
                        int M = 0;
                        while(i + M < n && (s[i + M] - '0')%2 != r && s[i + M] < s[m]) M++;
                        char am[i - m];
                        for(int j = 0; j < i - m; j++){
                            am[j] = s[m + j];
                        }
                        for(int j = 0; j<M; j++){
                            s[m + j] = s[i+j];
                        }
                        for(int j = 0; j < i - m; j++){
                            s[m + M + j] = am[j];
                        }
                        i += M-1;
                        change = true;
                    }
                    c.clear();
                    v.clear();
                    v.push_back({s[i],i});
                    c.insert(s[i]);
                    r = (s[i] - '0')%2;

                }
            }
        }
        cout << s << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        string s;
        cin >> s;
        queue<char> even, odd;
        for(char x : s){
            if((x - '0')%2) odd.push(x);
            else even.push(x);
        }
        string ans = "";
        while(!even.empty() && !odd.empty()){
            if(even.front() < odd.front()){
                ans += even.front();
                even.pop();
            }else{
                ans += odd.front();
                odd.pop();
            }
        }
        while(!even.empty()){
            ans += even.front();
            even.pop();
        }
        while(!odd.empty()){
            ans += odd.front();
            odd.pop();
        }
        cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int q;
    cin >> q;
    for(int k=0; k<q; k++){
        string s;
        cin >> s;
        vector< pair<int, int>> v;
        set<char> se;
        int n = int(s.size());
        bool change = true;
        while(change){
            change = false;
            int r = (s[0] - '0')%2;
            v.push_back({s[0],0});
            se.insert(s[0]);
            for(int i=1; i<n; i++){
                if((s[i] - '0')%2 == r){
                    if(se.count(s[i]) == 0){
                        v.push_back({s[i], i});
                        se.insert(s[i]);
                    }
                }else{
                    auto it = se.end();
                    it--;
                    if(s[i] < *it){
                        int m = i;
                        for(auto x : v){
                            if(s[i] < x.first) m = min(m, x.second);
                        }
                        char aux = s[m], aux1;
                        s[m] = s[i];
                        for(int j=m+1; j <= i; j++){
                            aux1 = s[j];
                            s[j] = aux;
                            aux = aux1;
                        }
                        change = i != m;
                    }
                    v.clear();
                    se.clear();
                    r = (s[i] - '0')%2;
                    v.push_back({s[i],i});
                    se.insert(s[i]);
                }
            }
        }
        cout << s << '\n';
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	int q;
	cin >> q;
	string s;
	for(int k=0; k<q; k++){
		cin >> s;
		int n = (int) s.size(), left =0, right = 0, r;
		queue<char> first, second;
		while(right < n){
			if(left == right){
				r = (s[left] - '0')%2;
				while(right < n && (s[right] - '0')%2 == r){
					first.push(s[right]);
					right++;
				}
			}else if(s[left] < s[right]){
				while(left < right && s[left] < s[right]){
					first.pop();
					left++;
				}
			}else{
				while(right < n && (s[right] - '0')%2 != r && s[right] < s[left]){
					second.push(s[right]);
					right++;
				}
				while(!second.empty()){
					s[left] = second.front();
					second.pop();
					left++;
				}
				while(!first.empty()){
					s[left] = first.front();
					first.pop();
					left++;
				}

			}
		}
		cout << s << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int q;
    cin >> q;
    for(int k=0; k<q; k++){
        string s;
        cin >> s;
        vector< pair<int, int>> v;
        set<char> se;
        int n = int(s.size()), r = (s[0] - '0')%2;
        v.push_back({s[0],0});
        se.insert(s[0]);
        for(int i=1; i<n; i++){
            if((s[i] - '0')%2 == r){
                if(se.count(s[i]) == 0){
                    v.push_back({s[i], i});
                    se.insert(s[i]);
                }
            }else{
                auto it = se.end();
                it--;
                if(s[i] < *it){
                    int m = i;
                    for(auto x : v){
                        if(s[i] < x.first) m = min(m, x.second);
                    }
                    char aux = s[m], aux1;
                    s[m] = s[i];
                    for(int j=m+1; j <= i; j++){
                        aux1 = s[j];
                        s[j] = aux;
                        aux = aux1;
                    }
                }
                v.clear();
                se.clear();
                r = (s[i] - '0')%2;
                v.push_back({s[i],i});
                se.insert(s[i]);
            }
        }
        cout << s << '\n';
    }
    return 0;
}


    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    typedef long long int ll;
    int main()
    {
        ll t,i,j,k,l;string  s;
        cin>>t;
        vector<char> o,e;
        while(t--)
        {
            cin>>s;
            o.clear();e.clear();
            for(i=0;i<s.length();i++)
            {
                if((s[i]-'0')&1)o.pb(s[i]);
                else e.pb(s[i]);
            }
            k=0;l=0;
            for(i=0;i<s.length();i++)
            {
                if(e[k]<o[l])
                {
                    cout<<e[k];
                    k++;
                }
                else{
                 cout<<o[l];l++;
                }
            }
            cout<<endl;
        }
        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    typedef long long int ll;
    int main()
    {
        ll t,i,j,k,l;string  s;
        cin>>t;
        vector<char> o,e;
        while(t--)
        {
            cin>>s;
            o.clear();e.clear();
            for(i=0;i<s.length();i++)
            {
                if((s[i]-'0')&1)o.pb(s[i]);
                else e.pb(s[i]);
            }
            o.pb(10);e.pb(10);
            k=0;l=0;
            for(i=0;i<s.length();i++)
            {
                if(e[k]<o[l])
                {
                    cout<<e[k];
                    k++;
                }
                else{
                 cout<<o[l];l++;
                }
            }
            cout<<endl;
        }
        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    typedef long long int ll;
    int main()
    {
        ll t,i,j,k,l;string  s;
        cin>>t;
        vector<int> o,e;
        while(t--)
        {
            cin>>s;
            o.clear();e.clear();
            for(i=0;i<s.length();i++)
            {
                if((s[i]-'0')&1)o.pb(s[i]-'0');
                else e.pb(s[i]-'0');
            }
            e.pb(10);o.pb(10);
            k=0;l=0;
            for(i=0;i<s.length();i++)
            {
                if(e[k]<o[l])
                {
                    s[i]=e[k]+'0';
                    k++;
                }
                else{
                 s[i]=o[l]+'0';l++;
                }
            }
            cout<<s<<endl;
        }
        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    typedef long long int ll;
    int main()
    {
        ll t,i,j,k,l;string  s;
        cin>>t;
        vector<char> o,e;
        while(t--)
        {
            cin>>s;
            o.clear();e.clear();
            for(i=0;i<s.length();i++)
            {
                if((s[i]-'0')&1)o.pb(s[i]);
                else e.pb(s[i]);
            }
            k=0;l=0;
            for(i=0;i<s.length();i++)
            {
                if(e[k]<o[l])
                {
                    cout<<e[k];
                    k++;
                }
                else{
                 cout<<o[l];l++;
                }
            }
            cout<<Endl;
        }
        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    typedef long long int ll;
    int main()
    {
        ll t,i,j,k,l;string  s;
        cin>>t;
        vector<char> o,e;
        while(t--)
        {
            cin>>s;
            o.clear();e.clear();
            for(i=0;i<s.length();i++)
            {
                if((s[i]-'0')&1)o.pb(s[i]);
                else e.pb(s[i]);
            }
            k=0;l=0;
            for(i=0;i<s.length();i++)
            {
                if(e[k]<o[l])
                {
                    cout<<e[k];
                    k++;
                }
                else{
                 cout<o[l];l++;
                }
            }
            cout<<endl;
        }
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
int main()
{
    ll t,i,j,k,l;string  s;
    cin>>t;
    vector<char> o,e;
    while(t--)
    {
        cin>>s;
        o.clear();e.clear();
        for(i=0;i<s.length();i++)
        {
            if((s[i]-'0')&1)o.pb(s[i]);
            else e.pb(s[i]);
        }
        k=0;l=0;
        for(i=0;i<s.length();i++)
        {
            if(e[k]<o[l])
            {
                cout<<e[k];
                k++;
            }
            else{
             cout<o[l];l++;
            }
        }
        cout<<Endl;
    }
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M){
  if(n==0)             return 1;
    else if(n%2 == 0)   return fastpower((x*x)%M,n/2,M);          // n is even
    else                return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
 }// n is odd
ll negativepow(ll base, ll expo, ll m) {
  if(m==1) return 0;
    ll ans=1,y=base%m;
    while(expo>0){
        if(expo&1)    ans=((ans)*y)%m;
        y=(y*y)%m;
        if(y<0) y+=m;
        expo=expo>>1;
    }
    if(ans<0){     ans=(m-abs(ans)%m);    return ans;    }
    return ans%m;
}
ll GCD(ll A, ll B) { if(B==0) return A;   else return GCD(B, A % B); }

bool vowl(char c){  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';}

ll modInverse(ll A,ll M){   return fastpower(A,M-2,M); }// m should be prime

void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}
void printDivisors(ll n)
{

    vector<ll> v;
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i==0)
        {
            if (n/i == i) // check if divisors are equal
                v.pb(i);
            else
            { v.pb(i);  // push the second divisor in the vector
                v.push_back(n/i);
            }
        }
    }
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
 {    return (a.second < b.second); }  //  sort(vect.begin(), vect.end(), sortbysec);

 void print(vll v)  {	for(auto it:v) cout<<it<<" "; cout<<"\n"; }

ll count_one (ll n)// count no of set bits number of 1
    {  ll count=0;  while( n ){ n = n&(n-1);  count++; }    return count;  }

ll sz(string s){ return s.length();}

int main()
{
	crap;
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t; cin>>t;
    while(t--)
    {
        string a; cin>>a;
        string s1,s2;
        for(int i=0;i<sz(a);i++)
        {
        	if( int(a[i]-'0')&1) s1+=a[i];
        	else s2+=a[i];
        }
        reverse(s1.begin(),s1.end());
        reverse(s2.begin(),s2.end());
        string res="";
        while( !(sz(s1)==0&&sz(s2)==0) )
          {
          	if(sz(s1)==0)
          	{
               res+=s2.back();
               s2.pop_back(); continue;
          	}
          	if(sz(s2)==0)
          	{
          		res+=s1.back(); s1.pop_back(); continue;
          	}
          	if(s1.back()<s2.back()){res+=s1.back(); s1.pop_back();}
          	else { res+=s2.back(); s2.pop_back(); }
          }
          cout<<res<<"\n";

    }
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M){
  if(n==0)             return 1;
    else if(n%2 == 0)   return fastpower((x*x)%M,n/2,M);          // n is even
    else                return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
 }// n is odd
ll negativepow(ll base, ll expo, ll m) {
  if(m==1) return 0;
    ll ans=1,y=base%m;
    while(expo>0){
        if(expo&1)    ans=((ans)*y)%m;
        y=(y*y)%m;
        if(y<0) y+=m;
        expo=expo>>1;
    }
    if(ans<0){     ans=(m-abs(ans)%m);    return ans;    }
    return ans%m;
}
ll GCD(ll A, ll B) { if(B==0) return A;   else return GCD(B, A % B); }

bool vowl(char c){  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';}

ll modInverse(ll A,ll M){   return fastpower(A,M-2,M); }// m should be prime

void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}
void printDivisors(ll n)
{

    vector<ll> v;
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i==0)
        {
            if (n/i == i) // check if divisors are equal
                v.pb(i);
            else
            { v.pb(i);  // push the second divisor in the vector
                v.push_back(n/i);
            }
        }
    }
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
 {    return (a.second < b.second); }  //  sort(vect.begin(), vect.end(), sortbysec);

 void print(vll v)  {	for(auto it:v) cout<<it<<" "; cout<<"\n"; }

ll count_one (ll n)// count no of set bits number of 1
    {  ll count=0;  while( n ){ n = n&(n-1);  count++; }    return count;  }

ll sz(string s){ return s.length();}

int main()
{
	crap;
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t; cin>>t;
    while(t--)
    {
        string s; cin>>s;
        string s1,s2;
        for(int i=0;i<sz(s);i++)
        {
        	if( (s[i]-'0')&1) s1+=s[i];
        	else s2+=s[i];
        }
        string res="";
        while( !(s1.empty()&&s2.empty()) )
          {
          	if(s1.empty())
          	{
               res+=s2.back();
               s2.pop_back(); continue;
          	}
          	if(s2.empty())
          	{
          		res+=s1.back(); s1.pop_back(); continue;
          	}
          	if(s1.back()<s2.back()){res+=s1.back(); s1.pop_back();}
          	else { res+=s2.back(); s2.pop_back(); }
          }
          cout<<res<<"\n";

    }
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M){
  if(n==0)             return 1;
    else if(n%2 == 0)   return fastpower((x*x)%M,n/2,M);          // n is even
    else                return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
 }// n is odd
ll negativepow(ll base, ll expo, ll m) {
  if(m==1) return 0;
    ll ans=1,y=base%m;
    while(expo>0){
        if(expo&1)    ans=((ans)*y)%m;
        y=(y*y)%m;
        if(y<0) y+=m;
        expo=expo>>1;
    }
    if(ans<0){     ans=(m-abs(ans)%m);    return ans;    }
    return ans%m;
}
ll GCD(ll A, ll B) { if(B==0) return A;   else return GCD(B, A % B); }

bool vowl(char c){  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';}

ll modInverse(ll A,ll M){   return fastpower(A,M-2,M); }// m should be prime

void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}
void printDivisors(ll n)
{

    vector<ll> v;
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i==0)
        {
            if (n/i == i) // check if divisors are equal
                v.pb(i);
            else
            { v.pb(i);  // push the second divisor in the vector
                v.push_back(n/i);
            }
        }
    }
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
 {    return (a.second < b.second); }  //  sort(vect.begin(), vect.end(), sortbysec);

 void print(vll v)  {	for(auto it:v) cout<<it<<" "; cout<<"\n"; }

ll count_one (ll n)// count no of set bits number of 1
    {  ll count=0;  while( n ){ n = n&(n-1);  count++; }    return count;  }

ll sz(string s){ return s.length();}

int main()
{
	crap;
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t; cin>>t;
    while(t--)
    {
        string s; cin>>s;
        string s1,s2;
        for(int i=0;i<sz(s);i++)
        {
        	if( (s[i]-'0')&1) s1+=s[i];
        	else s2+=s[i];
        }
        reverse(s1.begin(),s1.end());
        reverse(s2.begin(),s2.end());
        string res="";
        while( !(s1.empty()&&s2.empty()) )
          {
          	if(s1.empty())
          	{
               res+=s2.back();
               s2.pop_back(); continue;
          	}
          	if(s2.empty())
          	{
          		res+=s1.back(); s1.pop_back(); continue;
          	}
          	if(s1.back()<s2.back()){res+=s1.back(); s1.pop_back();}
          	else { res+=s2.back(); s2.pop_back(); }
          }
          cout<<res<<"\n";

    }
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M){
  if(n==0)             return 1;
    else if(n%2 == 0)   return fastpower((x*x)%M,n/2,M);          // n is even
    else                return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
 }// n is odd
ll negativepow(ll base, ll expo, ll m) {
  if(m==1) return 0;
    ll ans=1,y=base%m;
    while(expo>0){
        if(expo&1)    ans=((ans)*y)%m;
        y=(y*y)%m;
        if(y<0) y+=m;
        expo=expo>>1;
    }
    if(ans<0){     ans=(m-abs(ans)%m);    return ans;    }
    return ans%m;
}
ll GCD(ll A, ll B) { if(B==0) return A;   else return GCD(B, A % B); }

bool vowl(char c){  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';}

ll modInverse(ll A,ll M){   return fastpower(A,M-2,M); }// m should be prime

void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}
void printDivisors(ll n)
{

    vector<ll> v;
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i==0)
        {
            if (n/i == i) // check if divisors are equal
                v.pb(i);
            else
            { v.pb(i);  // push the second divisor in the vector
                v.push_back(n/i);
            }
        }
    }
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
 {    return (a.second < b.second); }  //  sort(vect.begin(), vect.end(), sortbysec);

 void print(vll v)  {	for(auto it:v) cout<<it<<" "; cout<<"\n"; }

ll count_one (ll n)// count no of set bits number of 1
    {  ll count=0;  while( n ){ n = n&(n-1);  count++; }    return count;  }

ll sz(string s){ return s.length();}

int main()
{
	crap;
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t; cin>>t;
    while(t--)
    {
        string a; cin>>a;
        string s1,s2;
        for(int i=0;i<sz(a);i++)
        {
        	if( int(a[i]-'0')&1) s1+=a[i];
        	else s2+=a[i];
        }
        reverse(s1.begin(),s1.end());
        reverse(s2.begin(),s2.end());
        string res="";
        while( !(sz(s1)==0&&sz(s2)==0) )
          {
          	if(s1.empty())
          	{
               res+=s2.back();
               s2.pop_back(); continue;
          	}
          	if(s2.empty())
          	{
          		res+=s1.back(); s1.pop_back(); continue;
          	}
          	if(s1.back()<s2.back()){res+=s1.back(); s1.pop_back();}
          	else { res+=s2.back(); s2.pop_back(); }
          }
          cout<<res<<"\n";

    }
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M){
  if(n==0)             return 1;
    else if(n%2 == 0)   return fastpower((x*x)%M,n/2,M);          // n is even
    else                return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
 }// n is odd
ll negativepow(ll base, ll expo, ll m) {
  if(m==1) return 0;
    ll ans=1,y=base%m;
    while(expo>0){
        if(expo&1)    ans=((ans)*y)%m;
        y=(y*y)%m;
        if(y<0) y+=m;
        expo=expo>>1;
    }
    if(ans<0){     ans=(m-abs(ans)%m);    return ans;    }
    return ans%m;
}
ll GCD(ll A, ll B) { if(B==0) return A;   else return GCD(B, A % B); }

bool vowl(char c){  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';}

ll modInverse(ll A,ll M){   return fastpower(A,M-2,M); }// m should be prime

void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}
void printDivisors(ll n)
{

    vector<ll> v;
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i==0)
        {
            if (n/i == i) // check if divisors are equal
                v.pb(i);
            else
            { v.pb(i);  // push the second divisor in the vector
                v.push_back(n/i);
            }
        }
    }
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
 {    return (a.second < b.second); }  //  sort(vect.begin(), vect.end(), sortbysec);

 void print(vll v)  {	for(auto it:v) cout<<it<<" "; cout<<"\n"; }

ll count_one (ll n)// count no of set bits number of 1
    {  ll count=0;  while( n ){ n = n&(n-1);  count++; }    return count;  }

ll sz(string s){ return s.length();}

int main()
{
	crap;
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t; cin>>t;
    while(t--)
    {
        string s; cin>>s;
        string s1,s2;
        for(int i=0;i<sz(s);i++)
        {
        	if( int(s[i]-'0')&1) s1+=s[i];
        	else s2+=s[i];
        }
        reverse(s1.begin(),s1.end());
        reverse(s2.begin(),s2.end());
        string res="";
        while( !(s1.empty()&&s2.empty()) )
          {
          	if(s1.empty())
          	{
               res+=s2.back();
               s2.pop_back(); continue;
          	}
          	if(s2.empty())
          	{
          		res+=s1.back(); s1.pop_back(); continue;
          	}
          	if(s1.back()<s2.back()){res+=s1.back(); s1.pop_back();}
          	else { res+=s2.back(); s2.pop_back(); }
          }
          cout<<res<<"\n";

    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int t;
string a;

int main() {
	cin >> t;
	for(int tc = 0; tc < t; ++tc){
		cin >> a;
		string s[2];
		for(auto x : a)
			s[int(x - '0') & 1] += x;

		reverse(s[0].begin(), s[0].end());
		reverse(s[1].begin(), s[1].end());

		string res = "";
		while(!(s[0].empty() && s[1].empty())){
			if(s[0].empty()){
				res += s[1].back();
				s[1].pop_back();
				continue;
			}
			if(s[1].empty()){
				res += s[0].back();
				s[0].pop_back();
				continue;
			}

			if(s[0].back() < s[1].back()){
				res += s[0].back();
				s[0].pop_back();
			}
			else{
				res += s[1].back();
				s[1].pop_back();
			}
		}

		cout << res << endl;
	}
	return 0;
}


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

int main()
{
    int t,i,a,b;
    cin>>t;
    string s;
    char w,x;
    while(t--)
    {
        vector <char> even,odd;
        cin>>s;
        a=0; b=0;
        for(i=0;i<s.length();i++)
        {
            if((int)s[i]%2==0) even.push_back(s[i]);
            else odd.push_back(s[i]);
        }
        for(i=0;i<s.length();i++)
        {
            if(!even.empty()&&a!=even.size()) w=even[a];
            else w=(char)(58);
            if(!odd.empty()&&b!=odd.size()) x=odd[b];
            else x=(char)(58);
            if(w>x)
            {
                cout<<x;
                b++;
            }
            else
            {
               cout<<w;
               a++;
            }
        }
        cout<<endl;
    }
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,i,a,b;
    vector <char> even,odd;
    cin>>t;
    string s;
    char w,x;
    while(t--)
    {
        cin>>s;
        a=0; b=0;
        for(i=0;i<s.length();i++)
        {
            if((int)s[i]%2==0) even.push_back(s[i]);
            else odd.push_back(s[i]);
        }
        for(i=0;i<s.length();i++)
        {
            if(!even.empty()&&a!=even.size()) w=even[a];
            else w=(char)(58);
            if(!odd.empty()&&b!=odd.size()) x=odd[b];
            else x=(char)(58);
            if(w>x)
            {
                cout<<x;
                b++;
            }
            else
            {
               cout<<w;
               a++;
            }
        }
        cout<<endl;
        even.clear(); odd.clear();
    }
}


#include<bits/stdc++.h>
using namespace std;
bool comp(char s1, char s2)
{
    return (s2>s1&&(s1-97)%2!=(s2-97)%2);
}
int main()
{
    int t,i;
    cin>>t;
    string s;
    while(t--)
    {
        cin>>s;
        sort(s.begin(),s.end(), comp);
        for(i=0;i<s.length();i++)
        cout<<s[i];
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
bool comp(char s1, char s2)
{
    return (s2>s1&&((int)s1)%2!=((int)s2)%2);
}
int main()
{
    int t,i;
    cin>>t;
    string s;
    while(t--)
    {
        cin>>s;
        sort(s.begin(),s.end(), comp);
        for(i=0;i<s.length();i++)
        cout<<s[i];
        cout<<endl;
    }
}


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

int main()
{
    int t,i,a,b;
    vector <char> even,odd;
    cin>>t;
    string s;
    char w,x;
    while(t--)
    {
        cin>>s;
        a=0; b=0;
        for(i=0;i<s.length();i++)
        {
            if((int)s[i]%2==0) even.push_back(s[i]);
            else odd.push_back(s[i]);
        }
        for(i=0;i<s.length();i++)
        {
            if(!even.empty()&&a!=even.size()) w=even[a];
            else w=(char)(58);
            if(!odd.empty()&&b!=odd.size()) x=odd[b];
            else x=(char)(58);
            if(w>x)
            {
                cout<<x;
                b++;
            }
            else
            {
               cout<<w;
               a++;
            }
        }
        cout<<endl;
        even.clear(); odd.clear();
    }
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
using namespace std;
void solve()
{
	string s;cin>>s;
	int n=s.length();
	int start=0,end=1;
	while(start<=end && end<n){
		int b=(s[end]-'0'),a=(s[start]-'0');
		if(a-b>0){
			if((a-b)%2){
				swap(s[start],s[end]);
				if(start!=0)start--;
				if(end!=1)end--;
			}
			else
			start++,end++;
		}
		else if(start>0&&(s[start-1]-'0')>b){
			swap(s[start],s[end]);
			start--,end--;
		}
		else
		start++,end++;
	}
	cout<<s<<'\n';
}
int main()
{
	int t;cin>>t;
	while(t--)
	solve();
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
using namespace std;
void solve()
{
	string s;cin>>s;
	int n=s.length();
	int start=0,end=1;
	while(start<=end && end<n){
		int a=(s[end]-'0'),b=(s[start]-'0');
		if(b-a>0){
			if((b-a)%2){
				swap(s[start],s[end]);
				if(start!=0)start--;
				if(end!=1)end--;
			}
			else
			start++,end++;
		}
		else{
			start++,end++;
		}
	}
	cout<<s<<'\n';
}
int main()
{
	int t;cin>>t;
	while(t--)
	solve();
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
using namespace std;
void solve()
{
	string str;cin>>str;
	string s[2];
	for(auto c:str){
		s[(c-'0')&1]+=c;
	}
	reverse(s[0].begin(),s[0].end());
	reverse(s[1].begin(),s[1].end());
	string res="";
	while(!(s[0].empty() && s[1].empty())){
		if(s[0].empty()){
			res+=s[1].back();
			s[1].pop_back();
			continue;
		}
		if(s[1].empty()){
			res+=s[0].back();
			s[0].pop_back();
			continue;
		}
		if(s[0].back() < s[1].back()){
			res+=s[0].back();
			s[0].pop_back();
		}
		else{
			res+=s[1].back();
			s[1].pop_back();

		}
	}

	cout<<res<<'\n';
}
int main()
{	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t;cin>>t;
	while(t--)
	solve();
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
using namespace std;
void solve()
{
	string s;cin>>s;
	int n=s.length();
	int start=0,end=1,last_reach=-1;
	while(start<=end && end<n){
		int b=(s[end]-'0'),a=(s[start]-'0');
		if(a==b){
			start++,end++;
			continue;
		}
		if(last_reach==-1)last_reach=a;
		else{
			if(a%2==last_reach%2)last_reach=max(last_reach,a);
			else
			last_reach=a;
		}
		if(a-b>0){
			if((a-b)%2){
				swap(s[start],s[end]);
				if(start!=0)start--;
				if(end!=1)end--;
			}
			else
			start++,end++;
		}
		else if(start>0&&(last_reach)>b && ((last_reach)-b)%2){
			swap(s[start],s[end]);
			start--,end--;
		}
		else
		start++,end++;
	}
	cout<<s<<'\n';
}
int main()
{
	int t;cin>>t;
	while(t--)
	solve();
}


#include<iostream>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
using namespace std;
void solve()
{
	string s;cin>>s;
	int n=s.length();
	int start=0,end=1,last_reach=-1;
	while(start<=end && end<n){
		if(s[start]==s[end])
		{
			start++,end++;
			continue;
		}

		int b=(s[end]-'0'),a=(s[start]-'0');

		if(last_reach==-1)last_reach=a;
		else{
			if(a%2==last_reach%2)last_reach=max(last_reach,a);
			else
			last_reach=a;
		}
		if(a-b>0){
			if((a-b)%2){
				swap(s[start],s[end]);
				if(start!=0)start--;
				if(end!=1)end--;
			}
			else
			start++,end++;
		}
		else if(start>0&&(last_reach)>b && ((last_reach)-b)%2){
			swap(s[start],s[end]);
			start--,end--;
		}
		else
		start++,end++;
	}
	cout<<s<<'\n';
}
int main()
{	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t;cin>>t;
	while(t--)
	solve();
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
using namespace std;
void solve()
{
	string s;cin>>s;
	int n=s.length();
	int start=0,end=1,last_reach=-1;
	while(start<=end && end<n){
		int b=(s[end]-'0'),a=(s[start]-'0');
		if(last_reach==-1)last_reach=a;
		else
		if(a%2==last_reach%2)last_reach=max(last_reach,a);
		else
		last_reach=a;
		if(a-b>0){
			if((a-b)%2){
				swap(s[start],s[end]);
				if(start!=0)start--;
				if(end!=1)end--;
			}
			else
			start++,end++;
		}
		else if(start>0&&(last_reach)>b && ((last_reach)-b)%2){
			swap(s[start],s[end]);
			start--,end--;
		}
		else
		start++,end++;
	}
	cout<<s<<'\n';
}
int main()
{
	int t;cin>>t;
	while(t--)
	solve();
}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
class dop
{public:
vector<vector<li>> a;
vector<li> b;
vector<bool> c;
li n,p,q,r,e;
string s,f;
void get();
};
void dop::get()
{cin>>s;
n=s.length();b.push_back(0);
for(li i=0;i<2;i++){a.push_back(b);}
for(li i=0;i<n;i++){c.push_back(true);}
for(li i=0;i<n;i++){if((s[i]-'0')%2==0){a[0].push_back(i);}else{a[1].push_back(i);}}
//for(li i=0;i<2;i++){for(li j=0;j<a[i].size();j++){cout<<a[i][j]<<" ";}cout<<'\n';}
for(li i=0;i<2;i++){a[i].erase(a[i].begin());}
f="";
p=q=0;
while(p<a[0].size()||q<a[1].size()){if(p!=a[0].size()&&q!=a[1].size()){if(s[a[0][p]]<s[a[1][q]]){f+=s[a[0][p]];p++;}
else{f+=s[a[1][q]];q++;}}
    else if(q!=a[1].size()){f+=s[a[1][q]];q++;}
    else if(p!=a[0].size()){f+=s[a[0][p]];p++;}
}cout<<f<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t=1;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
class dop
{public:
vector<vector<li>> a;
vector<li> b;
li n,p,q,r;
string s;
void get();
};
void dop::get()
{cin>>s;
n=s.length();b.push_back(0);
for(li i=0;i<2;i++){a.push_back(b);}
for(li i=0;i<n;i++){if((s[i]-'0')%2==0){a[0].push_back(i);}else{a[1].push_back(i);}}
//for(li i=0;i<2;i++){for(li j=0;j<a[i].size();j++){cout<<a[i][j]<<" ";}cout<<'\n';}
for(li i=0;i<2;i++){a[i].erase(a[i].begin());}
for(li i=0;i<n;i++){//if(s[i]=='0'){continue;}
if((s[i]-'0')%2!=0){r=0;}
else{r=1;}p=1e18;//cout<<r<<" "<<"a"<<" "<<i<<" ";
auto itr=upper_bound(a[r].begin(),a[r].end(),i);
    if(itr==a[r].end()||s[(*itr)]>s[i]){continue;}
    else{p=*itr;for(li j=p;j>i;j--){swap(s[j],s[j-1]);}}p=itr-a[r].begin();a[r].erase(a[r].begin()+p);p=*itr; // s.erase(s.begin()+p);i--;
   r=!r;itr=lower_bound(a[r].begin(),a[r].end(),i);q=itr-a[r].begin();
   auto ptr=lower_bound(a[r].begin(),a[r].end(),p);p=ptr-a[r].begin();
  // cout<<p<<" "<<q<<'\n';

   // for(li j=q;j<p;i++){a[r][j]++;}
 //for(li j=0;j<10;j++){for(li k=0;k<a[j].size();k++){if(a[j][k]>=i&&a[j][k]<p){a[j][k]++;}else if(a[j][k]==p){a[j][k]=i;}}}
  }cout<<s<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t=1;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
class dop
{public:
vector<vector<li>> a;
vector<li> b;
li n,p,q,r;
string s;
void get();
};
void dop::get()
{cin>>s;
n=s.length();b.push_back(0);
for(li i=0;i<2;i++){a.push_back(b);}
for(li i=0;i<n;i++){if((s[i]-'0')%2==0){a[0].push_back(i);}else{a[1].push_back(i);}}
//for(li i=0;i<2;i++){for(li j=0;j<a[i].size();j++){cout<<a[i][j]<<" ";}cout<<'\n';}
for(li i=0;i<2;i++){a[i].erase(a[i].begin());}
for(li i=0;i<n;i++){//if(s[i]=='0'){continue;}
if((s[i]-'0')%2!=0){r=0;}
else{r=1;}p=1e18;//cout<<r<<" "<<"a"<<" "<<i<<" ";
auto itr=upper_bound(a[r].begin(),a[r].end(),i);
    if(itr==a[r].end()||s[(*itr)]>s[i]){continue;}
    else{p=*itr;for(li j=p;j>i;j--){swap(s[j],s[j-1]);}}p=itr-a[r].begin();a[r][p]=i;p=*itr;
   r=!r;itr=lower_bound(a[r].begin(),a[r].end(),i);q=itr-a[r].begin();
   auto ptr=lower_bound(a[r].begin(),a[r].end(),p);p=ptr-a[r].begin();
  // cout<<p<<" "<<q<<'\n';
    for(li j=q;j<p;i++){a[r][j]++;}
 //for(li j=0;j<10;j++){for(li k=0;k<a[j].size();k++){if(a[j][k]>=i&&a[j][k]<p){a[j][k]++;}else if(a[j][k]==p){a[j][k]=i;}}}
  }cout<<s<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t=1;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
class dop
{public:
vector<vector<li>> a;
vector<li> b;
li n,p,q,r;
string s;
void get();
};
void dop::get()
{cin>>s;
n=s.length();b.push_back(0);
for(li i=0;i<10;i++){a.push_back(b);}
for(li i=0;i<n;i++){a[s[i]-'0'].push_back(i);}
for(li i=0;i<10;i++){a[i].erase(a[i].begin());}
for(li i=0;i<n;i++){if(s[i]=='0'){continue;}
if(s[i]%2!=0){r=0;}
else{r=1;}p=1e18;
for(li j=r;j<s[i]-'0';j+=2){
    auto itr=upper_bound(a[j].begin(),a[j].end(),i);
    if(itr!=a[j].end()){p=min(p,*itr);}}
    if(p==1e18){continue;}
    else{for(li j=p;j>i;j--){swap(s[j],s[j-1]);}}
 for(li j=0;j<10;j++){for(li k=0;k<a[j].size();k++){if(a[j][k]>=i&&a[j][k]<p){a[j][k]++;}else if(a[j][k]==p){a[j][k]=i;}}}
    }cout<<s<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t=1;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
class dop
{public:
vector<vector<li>> a;
vector<li> b;
li n,p,q,r;
string s;
void get();
};
void dop::get()
{cin>>s;
n=s.length();b.push_back(0);
for(li i=0;i<10;i++){a.push_back(b);}
for(li i=0;i<n;i++){a[s[i]-'0'].push_back(i);}
for(li i=0;i<10;i++){a[i].erase(a[i].begin());}
for(li i=0;i<n;i++){if(s[i]=='0'){continue;}
if(s[i]%2!=0){r=0;}
else{r=1;}p=1e18;
for(li j=r;j<10;j+=2){
    auto itr=upper_bound(a[j].begin(),a[j].end(),i);
    if(itr!=a[j].end()){p=min(p,*itr);}}
    if(p==1e18||s[p]>s[i]){continue;}
    else{for(li j=p;j>i;j--){swap(s[j],s[j-1]);}}
 for(li j=0;j<10;j++){for(li k=0;k<a[j].size();k++){if(a[j][k]>=i&&a[j][k]<p){a[j][k]++;}else if(a[j][k]==p){a[j][k]=i;}}}
   }cout<<s<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t=1;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <iostream>
using namespace std;
int toint(char x){
	return (int)(x-'0');
}
int main() {
	string a;
	int q;
	cin>>q;
	for( int i = 0; i < q; ++i){
		cin>>a;
		for(int n = 0; n < a.length(); ++n){
			for(int j = n+1; j < a.length(); ++j){
				if((toint(a[j])%2)!=(toint(a[n])%2)){
					if((toint(a[j])) < (toint(a[n]))){
						cout<<a[j];
						a.erase(j, 1);
						--j;
					}else{
						break;
					}
				}
			}
			cout<<a[n];
		}
		cout<<endl;
	}
	return 0;
}


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

int main() {
    int n, t, q;
    cin>>t;
    vector <int> a;
    vector <int> b;
    string c;
    for(int i = 0; i < t; ++i) {
     cin>>c;
     a.clear();
     b.clear();
     for(int j = 0; j < c.length(); ++j) {
      if((int)( c[j] -'0')%2) a.push_back((int)(c[j] -'0'));
      else b.push_back((int)(c[j] - '0'));
     }
     int x = 0, y = 0;
     a.push_back(10);
     b.push_back(10);
     while(a[x] != b[y]) {
      if(a[x] < b[y]) {
       cout<<a[x] ;
       ++x;
}
      else{
       cout<<b[y] ;
       ++y;
}
    }
}

	return 0;
}


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

int main() {
    int n, t, q;
    cin>>t;
    vector <int> a;
    vector <int> b;
    string c;
    for(int i = 0; i < t; ++i) {
     cin>>c;
     a.clear();
     b.clear();
     for(int j = 0; j < c.length(); ++j) {
      if((int)( c[j] -'0')%2) a.push_back((int)(c[j] -'0'));
      else b.push_back((int)(c[j] - '0'));
     }
     int x = 0, y = 0;
     a.push_back(10);
     b.push_back(10);
     while(a[x] != b[y]) {
      if(a[x] < b[y]) {
       cout<<a[x] ;
       ++x;
}
      else{
       cout<<b[y] ;
       ++y;
}
   }
cout<<endl;
}

	return 0;
}


#include <iostream>
using namespace std;
int toint(char x){
	return (int)(x-'0');
}
int main() {
	string a;
	int q;
	cin>>q;
	for( int i = 0; i < q; ++i){
		cin>>a;
		for(int n = 0; n < a.length(); ++n){
			if(n > 0){
				if((toint(a[n])%2) == (toint(a[n]-1)%2)){
					if((toint(a[n])) <= (toint(a[n]-1))){
						cout<<a[n];
					}else{
						for(int j = n+1; j < a.length(); ++j){
					if((toint(a[j])%2)!=(toint(a[n])%2)){
						if((toint(a[j])) < (toint(a[n]))){
							cout<<a[j];
							a.erase(j, 1);
							--j;
						}else{
							break;
						}
					}
				}
				cout<<a[n];
					}
				}else{
					for(int j = n+1; j < a.length(); ++j){
					if((toint(a[j])%2)!=(toint(a[n])%2)){
						if((toint(a[j])) < (toint(a[n]))){
							cout<<a[j];
							a.erase(j, 1);
							--j;
						}else{
							break;
						}
					}
				}
				cout<<a[n];
				}
			}else{
				for(int j = n+1; j < a.length(); ++j){
					if((toint(a[j])%2)!=(toint(a[n])%2)){
						if((toint(a[j])) < (toint(a[n]))){
							cout<<a[j];
							a.erase(j, 1);
							--j;
						}else{
							break;
						}
					}
				}
				cout<<a[n];
			}

		}
		cout<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int toint(char x){
	return (int)(x-'0');
}
int main() {
	string a;
	int q;
	cin>>q;
	for( int i = 0; i < q; ++i){
		cin>>a;
		for(int n = 0; n < a.length(); ++n){
			for(int j = n+1; j < a.length(); ++j){
				if((toint(a[j])%2)!=(toint(a[n])%2)){
					if((toint(a[j])) < (toint(a[n]))){
						cout<<a[j];
						a.erase(j, 1);
						--j;
					}
				}
			}
			cout<<a[n];
		}
		cout<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int toint(char x){
	return (int)(x-'0');
}
int main() {
	string a;
	int q;
	cin>>q;
	for( int i = 0; i < q; ++i){
		cin>>a;
		for(int n = 0; n < a.length(); ++n){
			if(n > 0){
				if((toint(a[n])%2) == (toint(a[n]-1)%2)){
					if((toint(a[n])) <= (toint(a[n]-1))){
						cout<<a[n];
					}else{
						for(int j = n+1; j < a.length(); ++j){
							if((toint(a[j])%2)!=(toint(a[n])%2)){
								if((toint(a[j])) < (toint(a[n]))){
									cout<<a[j];
									a.erase(j, 1);
									--j;
								}else{
									break;
								}
							}else if((toint(a[j])) < (toint(a[n]))) break;
						}
						cout<<a[n];
					}
				}else{
					for(int j = n+1; j < a.length(); ++j){
							if((toint(a[j])%2)!=(toint(a[n])%2)){
								if((toint(a[j])) < (toint(a[n]))){
									cout<<a[j];
									a.erase(j, 1);
									--j;
								}else{
									break;
								}
							}else if((toint(a[j])) < (toint(a[n]))) break;
						}
						cout<<a[n];
					}
			}else{
				for(int j = n+1; j < a.length(); ++j){
					if((toint(a[j])%2)!=(toint(a[n])%2)){
						if((toint(a[j])) < (toint(a[n]))){
							cout<<a[j];
							a.erase(j, 1);
							--j;
						}else{
							break;
						}
					}else if((toint(a[j])) < (toint(a[n]))) break;
				}
				cout<<a[n];
			}

		}
		cout<<endl;
	}
	return 0;
}


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

#define endl "\n"
#define int long long
#define uint unsigned long long
#define deb(x) cout << #x << " => " << x << "\n"
#define deba(x) cout << #x << "\n"; for (auto a : x) cout << a << " "; cout << "\n";
#define debm(x) cout << #x << "\n"; for (auto a : x) {for(auto b : a) cout << b << " "; cout << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pout cout << fixed << setprecision(10)
#define MOD (int) (1e9 + 7)

int fastpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

// void mergeSort(int arr[], int l, int r) {
//     if (r - l < 2) {
//         for (int i = l; i <= r; i++) {
//             for (int j = l; j < r; j++) {
//                 if ((arr[j] > arr[j + 1]) and ((arr[j] % 2) != (arr[j + 1] % 2))) {
//                     swap(arr[j], arr[j + 1]);
//                 }
//             }
//         }
//     // } else {
//     //     int m = l+(r-l)/2;
//     //     deb(arr[m]);
//     //     mergeSort(arr, l, m);
//     //     mergeSort(arr, m+1, r);
//     //     while ((arr[m] > arr[m + 1]) and ((arr[m] % 2) != (arr[m] % 2))) {
//     //         swap(arr[m], arr[m + 1]);
//     //         mergeSort(arr, l, m);
//     //         mergeSort(arr, m+1, r);
//     //     }

//     }
// }

int32_t main() {
    fastio;
    int t; cin >> t;
    while (t--) {
        string s; cin >> s;
        int n = s.length();
        int arr[n];
        int i = 0;
        for (auto x : s) {
            arr[i] = x - '0';
            i++;
        }
        // mergeSort(arr, 0, n - 1);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - 1; j++) {
                if ((arr[j] > arr[j + 1]) and ((arr[j] % 2) != (arr[j + 1] % 2))) {
                    swap(arr[j], arr[j + 1]);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            cout << arr[i];
        }
        cout << endl;
    }
    return 0;
}