#pragma clang diagnostic push #pragma ide diagnostic ignored "cppcoreguidelines-narrowing-conversions" #pragma ide diagnostic ignored "hicpp-signed-bitwise" #pragma GCC optimize ("Ofast,unroll-loops") #pragma GCC optimize("no-stack-protector,fast-math") #include using namespace std; typedef long long ll; typedef pair pll; typedef pair pii; typedef pair pdd; typedef vector vi; typedef vector vll; typedef vector vd; typedef vector vs; typedef vector vvi; typedef vector vvvi; typedef vector vvll; typedef vector vvvll; typedef vector vpii; typedef vector vvpii; typedef vector vpll; typedef vector vvpll; typedef vector vpdd; typedef vector vvd; #define yn(ans) printf("%s\n", (ans)?"Yes":"No"); #define YN(ans) printf("%s\n", (ans)?"YES":"NO"); template bool chmax(T &a, T b) { if (a >= b) return false; a = b; return true; } template bool chmin(T &a, T b) { if (a <= b) return false; a = b; return true; } #define FOR(i, s, e, t) for ((i) = (s); (i) < (e); (i) += (t)) #define REP(i, e) for (int i = 0; i < (e); ++i) #define REP1(i, s, e) for (int i = (s); i < (e); ++i) #define RREP(i, e) for (int i = (e); i >= 0; --i) #define RREP1(i, e, s) for (int i = (e); i >= (s); --i) #define all(v) v.begin(), v.end() #define pb push_back #define qb pop_back #define pf push_front #define qf pop_front #define maxe max_element #define mine min_element ll inf = 1e18; #define DEBUG printf("%d\n", __LINE__); fflush(stdout); template void print(vector &v, bool withSize = false) { if (withSize) cout << v.size() << endl; REP(i, v.size()) cout << v[i] << " "; cout << endl; } mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count()); int __FAST_IO__ = []() { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); return 0; }(); // Mint & Combinatorics template T inverse(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } return u; } template class Modular { public: using Type = typename decay::type; constexpr Modular() : value() {} template Modular(const U& x) { value = normalize(x); } template static Type normalize(const U& x) { Type v; if (-mod() <= x && x < mod()) v = static_cast(x); else v = static_cast(x % mod()); if (v < 0) v += mod(); return v; } const Type& operator()() const { return value; } template explicit operator U() const { return static_cast(value); } constexpr static Type mod() { return T::value; } Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; } Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; } template Modular& operator+=(const U& other) { return *this += Modular(other); } template Modular& operator-=(const U& other) { return *this -= Modular(other); } Modular& operator++() { return *this += 1; } Modular& operator--() { return *this -= 1; } Modular operator++(int) { Modular result(*this); *this += 1; return result; } Modular operator--(int) { Modular result(*this); *this -= 1; return result; } Modular operator-() const { return Modular(-value); } template typename enable_if::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) { #ifdef _WIN32 uint64_t x = static_cast(value) * static_cast(rhs.value); uint32_t xh = static_cast(x >> 32), xl = static_cast(x), d, m; asm( "divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod()) ); value = m; #else value = normalize(static_cast(value) * static_cast(rhs.value)); #endif return *this; } template typename enable_if::Type, long long>::value, Modular>::type& operator*=(const Modular& rhs) { long long q = static_cast(static_cast(value) * rhs.value / mod()); value = normalize(value * rhs.value - q * mod()); return *this; } template typename enable_if::Type>::value, Modular>::type& operator*=(const Modular& rhs) { value = normalize(value * rhs.value); return *this; } Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); } friend const Type& abs(const Modular& x) { return x.value; } template friend bool operator==(const Modular& lhs, const Modular& rhs); template friend bool operator<(const Modular& lhs, const Modular& rhs); template friend V& operator>>(V& stream, Modular& number); private: Type value; }; template bool operator==(const Modular& lhs, const Modular& rhs) { return lhs.value == rhs.value; } template bool operator==(const Modular& lhs, U rhs) { return lhs == Modular(rhs); } template bool operator==(U lhs, const Modular& rhs) { return Modular(lhs) == rhs; } template bool operator!=(const Modular& lhs, const Modular& rhs) { return !(lhs == rhs); } template bool operator!=(const Modular& lhs, U rhs) { return !(lhs == rhs); } template bool operator!=(U lhs, const Modular& rhs) { return !(lhs == rhs); } template bool operator<(const Modular& lhs, const Modular& rhs) { return lhs.value < rhs.value; } template Modular operator+(const Modular& lhs, const Modular& rhs) { return Modular(lhs) += rhs; } template Modular operator+(const Modular& lhs, U rhs) { return Modular(lhs) += rhs; } template Modular operator+(U lhs, const Modular& rhs) { return Modular(lhs) += rhs; } template Modular operator-(const Modular& lhs, const Modular& rhs) { return Modular(lhs) -= rhs; } template Modular operator-(const Modular& lhs, U rhs) { return Modular(lhs) -= rhs; } template Modular operator-(U lhs, const Modular& rhs) { return Modular(lhs) -= rhs; } template Modular operator*(const Modular& lhs, const Modular& rhs) { return Modular(lhs) *= rhs; } template Modular operator*(const Modular& lhs, U rhs) { return Modular(lhs) *= rhs; } template Modular operator*(U lhs, const Modular& rhs) { return Modular(lhs) *= rhs; } template Modular operator/(const Modular& lhs, const Modular& rhs) { return Modular(lhs) /= rhs; } template Modular operator/(const Modular& lhs, U rhs) { return Modular(lhs) /= rhs; } template Modular operator/(U lhs, const Modular& rhs) { return Modular(lhs) /= rhs; } template Modular power(const Modular& a, const U& b) { assert(b >= 0); Modular x = a, res = 1; U p = b; while (p > 0) { if (p & 1) res *= x; x *= x; p >>= 1; } return res; } template bool IsZero(const Modular& number) { return number() == 0; } template string to_string(const Modular& number) { return to_string(number()); } // U == std::ostream? but done this way because of fastoutput template U& operator<<(U& stream, const Modular& number) { return stream << number(); } // U == std::istream? but done this way because of fastinput template U& operator>>(U& stream, Modular& number) { typename common_type::Type, long long>::type x; stream >> x; number.value = Modular::normalize(x); return stream; } struct MOD { static int value; }; int MOD::value = 998244353; using Mint = Modular; typedef vector vm; typedef vector vvm; typedef vector vvvm; vector> readGraph(int N, int M, bool isDirected = false) { vector> g(N); REP(i, M) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); if (!isDirected) g[v].push_back(u); } return g; } #define TESTS int t; cin >> t; while (t--) #define TEST int main() { TEST { int N; cin >> N; vi A(N); REP(i, N) cin >> A[i]; if (N <= 4) { vi q(N); REP(i, N) q[i] = i + 1; map m; do { int x = 0; REP(i, N) x ^= A[i] + q[i]; m[x].pb(q); } while (next_permutation(all(q))); for (auto &e: m) { if (e.second.size() >= 2) { REP(i, N) printf("%d ", e.second[0][i]); printf("\n"); REP(i, N) printf("%d ", e.second[1][i]); printf("\n"); return 0; } } printf("-1\n"); } else { vvi p(4); REP(i, N) p[A[i] % 4].pb(i); vi ans(N, 0), ans2(N, 0); REP(i, 4) { if (p[i].size() >= 2) { if (i == 2) { ans[p[i][0]] = 2; ans[p[i][1]] = 3; ans2[p[i][0]] = 3; ans2[p[i][1]] = 2; int x = 1; REP(j, N) if (ans[j] == 0) { ans[j] = ans2[j] = x; if (x == 1) x = 4; else x++; } } else { ans[p[i][0]] = 1; ans[p[i][1]] = 2; ans2[p[i][0]] = 2; ans2[p[i][1]] = 1; int x = 3; REP(j, N) if (ans[j] == 0) { ans[j] = ans2[j] = x; x++; } } break; } } REP(i, N) printf("%d ", ans[i]); printf("\n"); REP(i, N) printf("%d ", ans2[i]); printf("\n"); } } return 0; }