#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 233;
struct node {
  int lm, rm, ma;
  int flag;
  int len;
  void go(int val) {
    if (val == 1)
      rm = lm = ma = 0;
    else
      lm = rm = ma = len;
    flag = val;
  }
} tree[N << 2];
int n, m, b, f;
int s[N], e[N];
void pushdown(int rt) {
  if (tree[rt].flag) {
    tree[rt << 1].go(tree[rt].flag);
    tree[rt << 1 | 1].go(tree[rt].flag);
    tree[rt].flag = 0;
  }
}
void pushup(int rt) {
  tree[rt].lm = tree[rt << 1].lm;
  tree[rt].rm = tree[rt << 1 | 1].rm;
  tree[rt].ma = max(tree[rt << 1].ma, tree[rt << 1 | 1].ma);
  if (tree[rt << 1].lm == tree[rt << 1].len)
    tree[rt].lm += tree[rt << 1 | 1].lm;
  if (tree[rt << 1 | 1].rm == tree[rt << 1 | 1].len)
    tree[rt].rm += tree[rt << 1].rm;
  tree[rt].ma = max(tree[rt].ma, max(tree[rt].lm, tree[rt].rm));
  tree[rt].ma = max(tree[rt].ma, tree[rt << 1].rm + tree[rt << 1 | 1].lm);
}
void build(int rt, int l, int r) {
  tree[rt].flag = 0;
  tree[rt].len = r - l;
  tree[rt].rm = tree[rt].lm = tree[rt].ma = tree[rt].len;
  if (l + 1 != r) {
    int mid = l + r >> 1;
    build(rt << 1, l, mid);
    build(rt << 1 | 1, mid, r);
  }
}
void update(int rt, int l, int r, int s, int e, int val) {
  if (s <= l && r <= e)
    tree[rt].go(val);
  else {
    pushdown(rt);
    int mid = l + r >> 1;
    if (s < mid) update(rt << 1, l, mid, s, e, val);
    if (e > mid) update(rt << 1 | 1, mid, r, s, e, val);
    pushup(rt);
  }
}
int query(int rt, int l, int r, int val) {
  pushdown(rt);
  int pos;
  int mid = l + r >> 1;
  if (tree[rt << 1].ma >= val)
    pos = query(rt << 1, l, mid, val);
  else if (tree[rt << 1].rm + tree[rt << 1 | 1].lm >= val)
    pos = mid - tree[rt << 1].rm;
  else
    pos = query(rt << 1 | 1, mid, r, val);
  pushup(rt);
  return pos;
}
int main() {
  while (scanf("%d%d%d%d", &n, &b, &f, &m) != EOF) {
    build(1, 0, n + b + f);
    for (int i = 1; i <= m; ++i) {
      int op, len;
      scanf("%d%d", &op, &len);
      if (op == 1) {
        if (tree[1].ma >= len + b + f) {
          int pos = query(1, 0, n + b + f, len + b + f) + b;
          s[i] = pos, e[i] = pos + len;
          update(1, 0, n + b + f, pos, pos + len, 1);
          printf("%d\n", pos - b);
        } else
          printf("-1\n");
      } else {
        update(1, 0, n + b + f, s[len], e[len], -1);
      }
    }
  }
  return 0;
}
