#include using namespace std; map SeatToIdx; map IdxToSeat; int main() { int n, k1, k2; cin >> n >> k1 >> k2; if(k1 < k2) { for(int i = k1, num = 0; i >= 1; --i) { SeatToIdx[i] = num; IdxToSeat[num] = i; num += 2; } for(int i = k2, num = 1; i <= n; ++i) { SeatToIdx[i] = num; IdxToSeat[num] = i; num += 2; } } else { for(int i = k1, num = 0; i <= n; ++i) { SeatToIdx[i] = num; IdxToSeat[num] = i; num += 2; } for(int i = k2, num = 1; i >= 1; --i) { SeatToIdx[i] = num; IdxToSeat[num] = i; num += 2; } } set ok; set notUsed; for(int i = 0; i < n; ++i) ok.insert(i); for(int i = 0; i < n; ++i) notUsed.insert(i); priority_queue, vector>, greater>> pq; int q; cin >> q; while(q--) { int64_t a, b; cin >> a >> b; bool used = false; while(pq.size()) { int64_t t, idx; tie(t, idx) = pq.top(); if(t > a) { if(ok.empty()) { if(notUsed.empty()) { a = t; continue; } } break; } pq.pop(); int seat = IdxToSeat[idx]; bool left = true, right = true; if(seat - 1 >= 1 and notUsed.find(SeatToIdx[seat - 1]) == notUsed.end()) { left = false; } if(seat + 1 <= n and notUsed.find(SeatToIdx[seat + 1]) == notUsed.end()) { right = false; } if(left and right) { ok.insert(idx); } notUsed.insert(idx); if(notUsed.find(SeatToIdx[seat - 1]) != notUsed.end()) { if(seat - 2 >= 1 and notUsed.find(SeatToIdx[seat - 2]) != notUsed.end()) { ok.insert(SeatToIdx[seat - 1]); } else if(seat - 2 == 0) { ok.insert(SeatToIdx[seat - 1]); } } if(notUsed.find(SeatToIdx[seat + 1]) != notUsed.end()) { if(seat + 2 <= n and notUsed.find(SeatToIdx[seat + 2]) != notUsed.end()) { ok.insert(SeatToIdx[seat + 1]); } else if(seat + 2 == n) { ok.insert(SeatToIdx[seat + 1]); } } } // cout << "OK" << '\n'; // for(int i : ok) { // cout << i << " "; // } // cout << '\n' << "Not Used" << '\n'; // for(int i : notUsed) { // cout << i << " "; // } // cout << '\n'; int idx, seat; if(ok.size()) { idx = *ok.begin(); seat = IdxToSeat[idx]; } else { idx = *notUsed.begin(); seat = IdxToSeat[idx]; } ok.erase(idx); notUsed.erase(idx); if(seat + 1 <= n) ok.erase(SeatToIdx[seat + 1]); if(seat - 1 >= 1) ok.erase(SeatToIdx[seat - 1]); pq.emplace(a + b, idx); cout << seat << '\n'; // cout << '\n'; } return 0; }