#include<bits/stdc++.h>
#include "meetings.h"
using namespace std;
mt19937 nsc(time(0));
inline void add_edge(int x,int y){
if(x>y)swap(x,y);
Bridge(x,y);
}
inline void solve(vector<int>q){
int n=q.size();
if(n==1)return;
if(n==2)return add_edge(q[0],q[1]),void();
shuffle(q.begin(),q.end(),nsc);
vector<pair<int,int> >a(n);
a[0]=make_pair(q[0],0),a[1]=make_pair(q[1],1);
for(int i=2;i<n;i++)a[i]=make_pair(Query(q[0],q[1],q[i]),i);
sort(a.begin(),a.end());
vector<int>qq;
for(int l=0,r=0;l<n;l=++r){
qq.push_back(a[l].first);
vector<int>cur(1,a[l].second);
while(r+1<n&&a[r+1].first==a[r].first)cur.push_back(a[++r].second);
solve(cur);
}
solve(qq);
}
inline void Solve(int N){
vector<int>q;
for(int i=0;i<N;i++)q.push_back(i);
solve(q);
}