#include "minerals.h"
#include<bits/stdc++.h>
using namespace std;
void Solve(int N) {
priority_queue<pair<pair<int,pair<int,int> >,int> > pq;
vector<int> v;
v.assign(2*N,0);
int c = 0;
int c1;
for (int i = 0;i<2*N;i++){
c1 = Query(i+1);
if (c1==c){
pq.push(make_pair(make_pair((i-1)/2,make_pair(i-1,0)),i));
}
else c++;
}
int t = 2*N-1;
while (!pq.empty()){
if (pq.top().first.second.first==pq.top().first.second.second ){
if (v[pq.top().second]==0){
Answer(pq.top().second+1,pq.top().first.second.first+1);
v[pq.top().second] = 1;
v[pq.top().first.second.first] = 1;
}
pq.pop();
continue;
}
while (t>pq.top().first.first) {c1 = Query(t+1);t--;}
while (t<pq.top().first.first){c1 = Query(t+1);t++;}
int d1 = Query(pq.top().second+1);
Query(pq.top().second+1);
if (c1==d1){
pair<pair<int,pair<int,int> >,int> x = pq.top();
pq.pop();
x.first.second.first = x.first.first;
x.first.first = (x.first.second.first+x.first.second.second)/2;
pq.push(x);
}
else{
pair<pair<int,pair<int,int> >,int> x = pq.top();
pq.pop();
x.first.second.second = x.first.first+1;
x.first.first = (x.first.second.first+x.first.second.second)/2;
pq.push(x);
}
}
}