#include <bits/stdc++.h>   using namespace std;   const int N = (1 << 20) + 10;   vector<pair<int, int>> g[N];   int tamp = 0;   bool faz;   namespace hpath_space {   vector<int> path;   vector<int> idit, used_edge;   void dfs(int no) {     while (1) {       int &id = idit[no];       while (id < (int)(g[no].size()) and used_edge[g[no][id].second]) id++;       if (id == (int)(g[no].size())) break;       used_edge[g[no][id].second] = 1;       int it = g[no][id++].first;       dfs(it);     }     if (faz) path.push_back(no);     tamp++;   }   bool has_cycle(int n, int m) {     int nimp = 0;     for (int i = 0; i < n; i++)       if ((int)(g[i].size()) & 1) nimp++;     tamp = 0;     if (nimp > 0) return 0;     int inic = 0;     for (int i = 0; i < n; i++)       if ((int)(g[i].size())) inic = i;     path.clear();     idit = vector<int>(n);     used_edge = vector<int>(m);     dfs(inic);     if (tamp == m + 1) return 1;     return 0;   }   };  // namespace hpath_space   int n;   vector<pair<int, int>> pe;   vector<int> ans;   template <class key_type, class value_type>   struct mymap {     int n;     vector<key_type> keys;     vector<value_type> values;     mymap(vector<key_type> _keys) {       keys = _keys;       sort((keys).begin(), (keys).end());       keys.resize(unique((keys).begin(), (keys).end()) - keys.begin());       n = (int)(keys.size());       values = vector<value_type>(n);     }     value_type &operator[](key_type key) {       int id = lower_bound((keys).begin(), (keys).end(), key) - keys.begin();       return values[id];     }   };   bool check(int k, bool sob = 1) {     faz = !sob;     int mask = (1 << k) - 1;     for (int i = 0; i < mask + 1; i++) g[i].clear();     for (int i = 0; i < n; i++) {       int ao, bo;       tie(ao, bo) = pe[i];       int a = ao & mask;       int b = bo & mask;       g[a].emplace_back(b, i);       g[b].emplace_back(a, i);     }     if (hpath_space::has_cycle(mask + 1, n)) {       if (sob) return 1;       vector<pair<int, int>> vmp, vst;       for (int i = 0; i < n; i++) {         int ao, bo;         tie(ao, bo) = pe[i];         int a = ao & mask;         int b = bo & mask;         vmp.emplace_back(a, b);         vmp.emplace_back(b, a);         vst.emplace_back(2 * i, 2 * i + 1);         vst.emplace_back(2 * i + 1, 2 * i);       }       mymap<pair<int, int>, vector<pair<int, int>>> mp(vmp);       mymap<pair<int, int>, int> mpid(vmp), st(vst);       for (int i = 0; i < n; i++) {         int ao, bo;         tie(ao, bo) = pe[i];         int a = ao & mask;         int b = bo & mask;         mp[{a, b}].push_back({2 * i, 2 * i + 1});         mp[{b, a}].push_back({2 * i + 1, 2 * i});       }       ans.clear();       vector<int> &path = hpath_space::path;       for (int i = 0; i < (int)(path.size()) - 1; i++) {         int va = path[i], vb = path[i + 1];         int &imp = mpid[{va, vb}];         int ia, ja;         auto &v = mp[{va, vb}];         while (1) {           tie(ia, ja) = v[imp];           if (st[{ia, ja}]) {             imp++;             continue;           }           st[{ia, ja}] = 1;           st[{ja, ia}] = 1;           break;         }         imp++;         ans.push_back(ia);         ans.push_back(ja);         assert(abs(ia - ja) == 1);       }       return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       pe.emplace_back(a, b);     }     int lo = 0, hi = 20;     while (lo < hi) {       int k = (lo + hi + 1) / 2;       if (hi - lo + 1 >= 8) k = lo + (hi - lo) / 3;       if (check(k))         lo = k;       else         hi = k - 1;     }     if (lo) {       int k = lo;       assert(check(k, 0));       assert((int)(ans.size()) == 2 * n);       cout << k <<   n ;       for (int i = 0; i < 2 * n; i++) {         if (i) cout <<    ;         cout << ans[i] + 1;       }       cout <<   n ;       return 0;     }     cout << 0 <<   n ;     for (int i = 0; i < 2 * n; i++) {       if (i) cout <<    ;       cout << i + 1;     }     cout <<   n ;   }