#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct node {
  int lft, rht;
  int lmx, rmx, mx, flag;
  int len() { return rht - lft; }
  int mid() { return (lft + ((rht - lft) >> 1)); }
  void init() { lmx = rmx = mx = len(); }
  void fun(int valu) {
    if (valu == 1)
      lmx = rmx = mx = 0;
    else
      lmx = rmx = mx = len();
    flag = valu;
  }
};
int n, m, b, f;
int st[N], ed[N];
struct Segtree {
  node tree[N * 4];
  void down(int ind) {
    if (tree[ind].flag) {
      tree[(ind << 1)].fun(tree[ind].flag);
      tree[(ind << 1 | 1)].fun(tree[ind].flag);
      tree[ind].flag = 0;
    }
  }
  void up(int ind) {
    tree[ind].lmx = tree[(ind << 1)].lmx;
    tree[ind].rmx = tree[(ind << 1 | 1)].rmx;
    tree[ind].mx = max(tree[(ind << 1)].mx, tree[(ind << 1 | 1)].mx);
    if (tree[(ind << 1)].lmx == tree[(ind << 1)].len())
      tree[ind].lmx += tree[(ind << 1 | 1)].lmx;
    if (tree[(ind << 1 | 1)].rmx == tree[(ind << 1 | 1)].len())
      tree[ind].rmx += tree[(ind << 1)].rmx;
    tree[ind].mx =
        max(tree[ind].mx, tree[(ind << 1)].rmx + tree[(ind << 1 | 1)].lmx);
    tree[ind].mx = max(tree[ind].mx, max(tree[ind].lmx, tree[ind].rmx));
  }
  void build(int lft, int rht, int ind) {
    tree[ind].lft = lft;
    tree[ind].rht = rht;
    tree[ind].flag = 0;
    tree[ind].init();
    if (lft + 1 != rht) {
      int mid = tree[ind].mid();
      build(lft, mid, (ind << 1));
      build(mid, rht, (ind << 1 | 1));
    }
  }
  void updata(int st, int ed, int ind, int valu) {
    int lft = tree[ind].lft, rht = tree[ind].rht;
    if (st <= lft && rht <= ed)
      tree[ind].fun(valu);
    else {
      down(ind);
      int mid = tree[ind].mid();
      if (st < mid) updata(st, ed, (ind << 1), valu);
      if (ed > mid) updata(st, ed, (ind << 1 | 1), valu);
      up(ind);
    }
  }
  int query(int valu, int ind) {
    down(ind);
    int pos;
    if (tree[(ind << 1)].mx >= valu)
      pos = query(valu, (ind << 1));
    else if (tree[(ind << 1)].rmx + tree[(ind << 1 | 1)].lmx >= valu)
      pos = tree[(ind << 1)].rht - tree[(ind << 1)].rmx;
    else
      pos = query(valu, (ind << 1 | 1));
    up(ind);
    return pos;
  }
} seg;
int main() {
  while (scanf("%d%d%d%d", &n, &b, &f, &m) != EOF) {
    seg.build(-b, n + f, 1);
    for (int i = 1; i <= m; i++) {
      int cmd, len, pos = -1;
      scanf("%d%d", &cmd, &len);
      if (cmd == 1) {
        if (seg.tree[1].mx >= len + b + f) {
          pos = seg.query(len + b + f, 1) + b;
          st[i] = pos, ed[i] = pos + len;
          seg.updata(st[i], ed[i], 1, 1);
        }
        printf("%d\n", pos);
      } else {
        seg.updata(st[len], ed[len], 1, -1);
      }
    }
  }
  return 0;
}
