#include <iostream>
#include <cstring>
#include <random>
#include <ctime>
#include <fstream>
#include <stack>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <unordered_map>
using namespace std;
namespace author {
    unordered_set<long long> m;
    inline long long solve(vector<long long>& a) {
        int n=a.size();
        long long mask=0, mask1=0;
        for(int j = 60; j >= 0; j--) {
            m.clear();
            mask1=((1LL<<61) - 1) - ((1LL<<j) - 1);
            for(int i = 1; i <= n; i++) m.insert(a[i-1]&mask1);
            for(int i = 1; i <= n; i++) {
                if(m.count((a[i-1]&mask1)^(mask|(1LL<<j)))) {
                    mask|=(1LL<<j);
                    break;
                }
            }
        }
        return mask;
    }
}
mt19937_64 mt(random_device{}());
vector<pair<pair<int, int>, long long>> gen_tree(int root, vector<long long>& dist) {
    int n = dist.size();
    vector<pair<pair<int, int>, long long>> ans;
    vector<int> p(n);
    p[0]=root;
    int ptr=1;
    for(int i = 1; i <= n; i++) if(i!=root) p[ptr++]=i;
    shuffle(p.begin()+1, p.end(), mt);
    for(int i = 1; i < n; i++) {
        int par = p[mt() % i], node = p[i];
        ans.push_back({{par, node}, dist[node-1]^dist[par-1]});
        if(mt()%2) swap(ans.back().first.first, ans.back().first.second);
    }
    shuffle(ans.begin(), ans.end(), mt);
    return ans;
}
vector<pair<pair<int, int>, long long>> gen_path(int root, vector<long long>& dist) {
    int n = dist.size();
    vector<pair<pair<int, int>, long long>> ans;
    for(int i = 2; i <= n; i++)
        ans.push_back({{i-1, i}, dist[i-1]^dist[i-2]});
    return ans;
}
vector<long long> gen_dist(int n, int root, int w, int c, int s) {
    w=min(w, 60); s=min(s, w); c=min(c, n); c=max(c, 1);
    long long l = (1LL<<s)-1, r = ((1LL<<w)-1)^l;
    vector<long long> b(c);
    for(int i = 0; i < c; i++) b[i] = mt() & r;
    vector<long long> d(n);
    for(int i = 0; i < n; i++) d[i] = b[mt()%c] | (mt() & l);
    d[root-1] = 0;
    return d;
}
void gen(int t, int n, int w, int c, int s) {
    ofstream in((string)"maxor." + (t<=9?"0":"") + to_string(t) + (string)".in");
    ofstream out((string)"maxor." + (t<=9?"0":"") + to_string(t) + (string)".out");
    in << n << endl;
    
    int root = mt()%n+1;
    vector<long long> dist = gen_dist(n, root, w, c, s); 
    auto tree = gen_tree(root, dist);
    for(auto &x : tree) {
        in << x.first.first << " " << x.first.second << " " << x.second << endl;
    }
    in << endl;
    out << author::solve(dist) << endl;
    in.close();
    out.close();
}
void gen_path(int t, int n, int w, int c, int s) {
    ofstream in((string)"maxor." + (t<=9?"0":"") + to_string(t) + (string)".in");
    ofstream out((string)"maxor." + (t<=9?"0":"") + to_string(t) + (string)".out");
    in << n << endl;
    
    int root = 1;
    vector<long long> dist = gen_dist(n, root, w, c, s); 
    auto tree = gen_path(root, dist);
    for(auto &x : tree) {
        in << x.first.first << " " << x.first.second << " " << x.second << endl;
    }
    in << endl;
    out << author::solve(dist) << endl;
    in.close();
    out.close();
}
int main() {
    // subtask 1
    gen(2, 1000, 59, 64, 20);
    gen(3, 1000, 59, 64, 20);
    gen(4, 1000, 59, 64, 20);
    gen(5, 1000, 59, 64, 20);
    gen(6, 1000, 59, 64, 20);
    gen(7, 1000, 59, 64, 20);

    // subtask 2 - path
    //gen(8, 14, 12, 8, 2);
    gen_path(9, 100000, 12, 8, 4);
    gen_path(10, 500, 12, 8, 4);
    gen_path(11, 20, 12, 3, 6);
    gen_path(12, 100000, 12, 1, 12);
    gen_path(13, 100000, 12, 1, 12);

    // subtask 3 - path
    //gen(14, 16, 15, 8, 4);
    gen_path(15, 60, 15, 64, 4);
    gen_path(16, 600, 15, 8, 4);
    gen_path(17, 100000, 15, 8, 4);
    gen_path(18, 100000, 15, 1, 15);

    // subtask 4 - path
    //gen(19, 16, 20, 8, 4);
    gen_path(20, 100000, 20, 1, 20);
    gen_path(21, 60, 20, 64, 4);
    gen_path(22, 600, 20, 1, 20);
    gen_path(23, 100000, 20, 8, 4);
    gen_path(24, 100000, 20, 4, 0);
    gen_path(25, 100000, 20, 512, 8);

    // subtask 5 - path
    //gen(26, 100000, 59, 1, 60);
    gen_path(27, 100000, 59, 64, 20);
    gen_path(28, 100000, 59, 1024, 8);
    gen_path(29, 100000, 59, 2, 40);
    gen_path(30, 100000, 59, 1, 30);
    gen_path(31, 100000, 59, 4, 0);
    gen_path(32, 100000, 59, 1, 60);

    // subtask 2 (6)
    gen(33, 20, 12, 3, 6);
    gen(34, 500, 12, 8, 4);
    gen(35, 100000, 12, 8, 4);
    gen(36, 100000, 12, 1, 12);

    // subtask 3 (7)
    gen(37, 60, 15, 64, 4);
    gen(38, 600, 15, 8, 4);
    gen(39, 100000, 15, 8, 4);
    gen(40, 100000, 15, 1, 15);

    // subtask 4 (8)
    gen(41, 60, 20, 64, 4);
    gen(42, 600, 20, 1, 20);
    gen(43, 100000, 20, 8, 4);
    gen(44, 100000, 20, 1, 20);
    gen(45, 100000, 20, 4, 0);
    gen(46, 100000, 20, 512, 8);

    // subtask 5 (9)
    gen(47, 100000, 59, 64, 20);
    gen(48, 100000, 59, 1024, 8);
    gen(49, 100000, 59, 2, 40);
    gen(50, 100000, 59, 1, 30);
    gen(51, 100000, 59, 4, 0);
    gen(52, 100000, 59, 1, 60);
}