#include #include #include #include #include using namespace std; #define inRange(x,a,b) (a <= x && x <= b) typedef long long ll; int main(){ int n, k1, k2; cin >> n >> k1 >> k2; double ent = k1 > k2 ? k1-0.2 : k1+0.2; vector fil(n+1, 0); priority_queue> ok1, ok2; for(int i = 1; i <= n; i++) ok1.push({-fabs(ent-i), i}); for(int i = 1; i <= n; i++) ok2.push({-fabs(ent-i), i}); // time, enter -1, exit 0, id priority_queue, int>> event; int q; cin >> q; vector a(q+1), b(q+1); for(int i = 1; i <= q; i++){ cin >> a[i] >> b[i]; event.push({{-a[i], -1}, i}); } vector ans(q+1); queue wait; auto f = [&](int i)->bool{ for(int j = -1; j <= 1; j++){ if(inRange(i+j, 1, n)&&fil[i+j]) return false; } return true; }; while(!event.empty()){ auto p = event.top(); event.pop(); ll tim = -p.first.first; int stat = p.first.second, ind = p.second; if(ind <= 0) ind += q; if(stat == 0){ int pos = ans[ind]; fil[pos] = false; if(!wait.empty()){ int now = wait.front(); wait.pop(); event.push({{-tim, -1}, now-q}); } for(int j = -1; j <= 1; j++){ if(inRange(pos+j,1,n)&&!fil[pos+j]){ if(f(pos+j)) ok1.push({-fabs(ent-(pos+j)), pos+j}); else ok2.push({-fabs(ent-(pos+j)), pos+j}); } } }else{ int sit = -1; while(!ok1.empty()){ auto p = ok1.top(); ok1.pop(); if(!fil[p.second] && f(p.second)){ sit = p.second; break; } } if(sit == -1){ while(!ok2.empty()){ auto p = ok2.top(); ok2.pop(); if(!fil[p.second]){ sit = p.second; break; } } } if(sit == -1){ wait.push(ind); continue; } ans[ind] = sit; fil[sit] = true; event.push({{-(tim+b[ind]), 0}, ind}); } } for(int i = 1; i <= q; i++) cout << ans[i] << endl; return 0; }