#include <bits/stdc++.h>
using namespace std;
// --------- 64-bit deterministic hash (splitmix64) ----------
static inline uint64_t splitmix64(uint64_t x){
x += 0x9e3779b97f4a7c15ULL;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ULL;
x = (x ^ (x >> 27)) * 0x94d049bb133111ebULL;
x ^= (x >> 31);
return x;
}
// Public hash for number j with small seed s (0..15)
static inline uint64_t H(int j, int s){
// deterministic, no RNG
uint64_t x = (uint64_t)j * 0x9e3779b97f4a7c15ULL
^ (uint64_t)(s + 0x9e3779b9) * 0xbf58476d1ce4e5b9ULL
^ 0x94d049bb133111ebULL;
return splitmix64(x);
}
// --------- XOR linear basis over GF(2) with reconstruction ----------
struct XorBasis {
// basis[b] has pivot at bit b (0..63)
uint64_t basis[64]{};
// comb[b] tells which columns (as bitset) compose basis[b]
array< bitset<128>, 64 > comb;
void clear(){
memset(basis, 0, sizeof(basis));
for(auto &c: comb) c.reset();
}
// insert vector v with column mask m; returns true if inserted (independent)
bool insert(uint64_t v, const bitset<128>& m){
uint64_t x = v;
bitset<128> mask = m;
for(int b=63; b>=0; --b){
if(((x>>b)&1ULL)==0) continue;
if(!basis[b]){
basis[b]=x; comb[b]=mask;
return true;
}
x ^= basis[b];
mask ^= comb[b];
}
return false; // dependent
}
// try represent target; if possible, fills mask (which columns XOR to target)
bool represent(uint64_t target, bitset<128>& mask) const {
mask.reset();
uint64_t t = target;
for(int b=63; b>=0; --b){
if(((t>>b)&1ULL)==0) continue;
if(!basis[b]) return false; // cannot reduce this bit
t ^= basis[b];
mask ^= comb[b];
}
return (t==0);
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
if(!(cin >> T)) return 0;
if(T==1){
int N; unsigned long long X;
cin >> N >> X; // N=100, X <= 1e18 < 2^60
vector<pair<int,int>> card(N);
for(int i=0;i<N;i++){
int a,b; cin>>a>>b;
card[i]={a,b};
}
// Try seeds s = 0..15. Target encodes [ top4=s | low60=X ].
const int SEED_BITS = 4;
const int MAX_SEED = (1<<SEED_BITS);
uint64_t answer_seed = ULLONG_MAX;
bitset<128> pickMask; // which columns choose b_i (y_i=1)
vector<uint64_t> d(N);
vector<uint64_t> baseHash(N);
// To avoid recomputing too much, we'll loop seeds and solve basis each time.
for(int s=0; s<MAX_SEED; ++s){
XorBasis xb; xb.clear();
uint64_t base = 0;
for(int i=0;i<N;i++){
uint64_t ha = H(card[i].first, s);
uint64_t hb = H(card[i].second, s);
baseHash[i] = ha; // assume pick a_i by default
d[i] = ha ^ hb; // column vector for variable y_i
base ^= ha;
}
uint64_t target = ((uint64_t)s << 60) ^ (uint64_t)X ^ base;
// build basis
for(int i=0;i<N;i++){
bitset<128> col; col.reset(); col.set(i);
xb.insert(d[i], col);
}
bitset<128> m;
if(xb.represent(target, m)){
answer_seed = (uint64_t)s;
pickMask = m;
break;
}
}
// Extremely unlikely, but as a safety net, if none worked, fall back s=0 and try greedy:
if(answer_seed == ULLONG_MAX){
// deterministic fallback: s=0 with basis solve again (should almost never fail)
int s = 0;
XorBasis xb; xb.clear();
uint64_t base=0;
for(int i=0;i<N;i++){
uint64_t ha = H(card[i].first, s);
uint64_t hb = H(card[i].second, s);
baseHash[i] = ha;
d[i] = ha ^ hb;
base ^= ha;
}
uint64_t target = ((uint64_t)s << 60) ^ (uint64_t)X ^ base;
for(int i=0;i<N;i++){
bitset<128> col; col.reset(); col.set(i);
xb.insert(d[i], col);
}
bitset<128> m;
bool ok = xb.represent(target, m);
// If still not ok, the instance is astronomically unlucky; but we proceed with m as zero.
if(ok) pickMask = m;
answer_seed = 0;
}
// Output selection according to pickMask: 0 -> pick a_i, 1 -> pick b_i
int s = (int)answer_seed;
vector<int> out(N);
for(int i=0;i<N;i++){
if(pickMask.test(i)) out[i] = card[i].second;
else out[i] = card[i].first;
}
for(int i=0;i<N;i++){
if(i) cout << ' ';
cout << out[i];
}
cout << '\n';
}
else if(T==2){
int N; cin >> N;
vector<int> xs(N);
for(int i=0;i<N;i++) cin >> xs[i]; // sorted ascending
const int SEED_BITS = 4;
const int MAX_SEED = (1<<SEED_BITS);
// Try all seeds; the correct one s will satisfy: (XOR H_s(x_i)) >> 60 == s
for(int s=0; s<MAX_SEED; ++s){
uint64_t acc = 0;
for(int v: xs) acc ^= H(v, s);
uint64_t seed_top = acc >> 60;
if((int)seed_top == s){
uint64_t X = acc & ((1ULL<<60) - 1ULL);
cout << X << '\n';
return 0;
}
}
// Practically unreachable; if happens, default to s=0.
{
int s = 0;
uint64_t acc = 0;
for(int v: xs) acc ^= H(v, s);
uint64_t X = acc & ((1ULL<<60) - 1ULL);
cout << X << '\n';
}
}
return 0;
}