#include <bits/stdc++.h>
using namespace std;
struct Node {
  int left, right;
  int cnt, lsum, rsum, msum;
  int len() { return right - left; }
  void init() { lsum = rsum = msum = len(); }
  void fun(int tmp) {
    if (tmp == 1)
      lsum = rsum = msum = 0;
    else
      lsum = rsum = msum = len();
    cnt = tmp;
  }
} node[100010 << 2];
void PushDown(int p) {
  if (node[p].cnt) {
    node[(p << 1)].fun(node[p].cnt);
    node[(p << 1 | 1)].fun(node[p].cnt);
    node[p].cnt = 0;
  }
}
void PushUp(int p) {
  node[p].lsum = node[(p << 1)].lsum;
  node[p].rsum = node[(p << 1 | 1)].rsum;
  node[p].msum = max(node[(p << 1)].msum, node[(p << 1 | 1)].msum);
  if (node[(p << 1)].lsum == node[(p << 1)].len())
    node[p].lsum += node[(p << 1 | 1)].lsum;
  if (node[(p << 1 | 1)].rsum == node[(p << 1 | 1)].len())
    node[p].rsum += node[(p << 1)].rsum;
  node[p].msum =
      max(node[p].msum, node[(p << 1)].rsum + node[(p << 1 | 1)].lsum);
  node[p].msum = max(node[p].msum, max(node[p].lsum, node[p].rsum));
}
void Build(int l, int r, int p) {
  node[p].left = l;
  node[p].right = r;
  node[p].cnt = 0;
  node[p].init();
  if (l + 1 != r) {
    int mid = (l + r) >> 1;
    Build(l, mid, p << 1);
    Build(mid, r, p << 1 | 1);
  }
}
void Update(int L, int R, int p, int valu) {
  int l = node[p].left, r = node[p].right;
  if (L <= l && R >= r)
    node[p].fun(valu);
  else {
    PushDown(p);
    int mid = (l + r) >> 1;
    if (L < mid) Update(L, R, (p << 1), valu);
    if (R > mid) Update(L, R, (p << 1 | 1), valu);
    PushUp(p);
  }
}
int Query(int m, int p) {
  int l = node[p].left, r = node[p].right;
  if (l == r)
    return node[p].left;
  else {
    PushDown(p);
    int pos;
    int mid = (l + r) >> 1;
    if (node[(p << 1)].msum >= m)
      pos = Query(m, (p << 1));
    else if (node[(p << 1)].rsum + node[(p << 1 | 1)].lsum >= m)
      pos = node[(p << 1)].right - node[(p << 1)].rsum;
    else
      pos = Query(m, (p << 1 | 1));
    PushUp(p);
    return pos;
  }
}
int st[100010], ed[100010];
int n, m, b, f;
int main() {
  while (~scanf("%d%d%d%d", &n, &b, &f, &m)) {
    Build(-b, n + f, 1);
    for (int i = 1; i <= m; i++) {
      int op, a, pos = -1;
      scanf("%d%d", &op, &a);
      if (op == 1) {
        if (node[1].msum >= a + b + f) {
          pos = Query(a + b + f, 1) + b;
          st[i] = pos, ed[i] = pos + a;
          Update(st[i], ed[i], 1, 1);
        }
        printf("%d\n", pos);
      } else {
        Update(st[a], ed[a], 1, -1);
      }
    }
  }
  return 0;
}
