#include<bits/stdc++.h>
#include "island.h"
using namespace std;
void solve(int N, int L) {
vector<int> first(N+1), second(N+1);
vector<pair<int, int>> ans;
for(int i=1; i<=N; i++) {
first[i]=query(i, 1);
ans.push_back({min(first[i], i), max(first[i], i)});
second[i]=query(i, 2);
}
for(int i=1; i<=N; i++) {
if(second[i] == first[first[i]]) continue;
else if(second[i] != second[first[i]]) {
ans.push_back({min(second[i], i), max(second[i], i)});
} else {
if(first[second[i]] == i) {
ans.push_back({min(second[i], i), max(second[i], i)});
} else if(first[second[i]] == first[i]) {
ans.push_back({min(second[i], first[i]), max(second[i], first[i])});
} else if(second[second[i]] == i) {
ans.push_back({min(second[i], i), max(second[i], i)});
} else {
ans.push_back({min(second[i], first[i]), max(second[i], first[i])});
}
}
}
sort(ans.begin(), ans.end());
for(int i=0; i<ans.size(); i++) {
if(i != 0 && ans[i] == ans[i-1]) continue;
// cerr << ans[i].first << ' ' << ans[i].second << endl;
answer(ans[i].first, ans[i].second);
}
}