#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 300;
int n, d, f, m;
struct Node {
  int tag, siz;
  int pre, mid, suf;
  void init(const int &val) {
    tag = val;
    pre = mid = suf = siz * val;
  }
  void merge(const Node &ls, const Node &rs) {
    pre = ls.pre + (ls.pre == ls.siz) * rs.pre;
    suf = rs.suf + (rs.suf == rs.siz) * ls.suf;
    mid = max(ls.mid, rs.mid);
    mid = max(mid, ls.suf + rs.pre);
  }
};
struct Tree {
  static const int N = ::N << 2;
  Node T[N];
  int n;
  int ls(int o) { return o << 1; }
  int rs(int o) { return o << 1 | 1; }
  void update(int o, int l, int r) { T[o].merge(T[ls(o)], T[rs(o)]); }
  void build(int o, int l, int r) {
    T[o].siz = r - l + 1;
    T[o].init(1);
    T[o].tag = -1;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(ls(o), l, mid);
    build(rs(o), mid + 1, r);
  }
  void init(int _n) {
    n = _n;
    build(1, 1, n);
  }
  void pushdown(int o, int l, int r) {
    if (!~T[o].tag) return;
    T[ls(o)].init(T[o].tag);
    T[rs(o)].init(T[o].tag);
    T[o].tag = -1;
  }
  void _change(int o, int l, int r, const int &ql, const int &qr,
               const int &qv) {
    if (ql <= l && qr >= r) {
      T[o].init(qv);
      return;
    } else {
      pushdown(o, l, r);
      int mid = (l + r) >> 1;
      if (ql <= mid) _change(ls(o), l, mid, ql, qr, qv);
      if (qr > mid) _change(rs(o), mid + 1, r, ql, qr, qv);
      update(o, l, r);
    }
  }
  void change(const int &ql, const int &qr, const int &qv) {
    assert(ql <= qr);
    assert(qv == 0 || qv == 1);
    _change(1, 1, n, ql, qr, qv);
  }
  int _query(int o, int l, int r, const int &qv) {
    if (l == r) return l;
    pushdown(o, l, r);
    int mid = (l + r) >> 1;
    if (T[ls(o)].mid >= qv) return _query(ls(o), l, mid, qv);
    if (T[ls(o)].suf + T[rs(o)].pre >= qv) return mid - T[ls(o)].suf + 1;
    if (T[rs(o)].mid >= qv) return _query(rs(o), mid + 1, r, qv);
    assert(1 == 0);
  }
  int query(const int &qv) {
    if (T[1].mid < qv) return -1;
    return _query(1, 1, n, qv);
  }
} tree;
int main() {
  cin >> n >> d >> f >> m;
  tree.init(n + d + f);
  vector<pair<int, int> > car;
  car.resize(m);
  for (int i = (0); i < (m); i++) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      pair<int, int> &u = car[i];
      scanf("%d", &u.first);
      u.second = tree.query(u.first + d + f);
      if (~u.second) {
        u.second += d;
        tree.change(u.second, u.second + u.first - 1, 0);
      }
      printf("%d\n", !~u.second ? -1 : u.second - d - 1);
    } else {
      int id;
      scanf("%d", &id);
      id--;
      pair<int, int> u = car[id];
      assert(u.second != -1);
      tree.change(u.second, u.second + u.first - 1, 1);
    }
  }
  return 0;
}
