#include <bits/stdc++.h>
using namespace std;
const int maxn = 101002;
struct node {
  int l, r;
} chu[600];
struct node2 {
  int ls, rs, ms;
  int l, r, len;
  int cnt;
} s[maxn << 2];
void pushup(int rt) {
  s[rt].ls = s[rt << 1].ls;
  s[rt].rs = s[rt << 1 | 1].rs;
  if (s[rt << 1].len == s[rt << 1].ls) {
    s[rt].ls += s[rt << 1 | 1].ls;
  }
  if (s[rt << 1 | 1].len == s[rt << 1 | 1].rs) {
    s[rt].rs += s[rt << 1].rs;
  }
  s[rt].ms = max(max(s[rt << 1].ms, s[rt << 1 | 1].ms),
                 s[rt << 1].rs + s[rt << 1 | 1].ls);
}
void build(int l, int r, int rt) {
  s[rt].cnt = -1;
  s[rt].l = l;
  s[rt].r = r;
  s[rt].len = (r - l + 1);
  s[rt].ls = s[rt].rs = s[rt].ms = (r - l + 1);
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  pushup(rt);
}
void pushdown(int rt) {
  if (s[rt].cnt != -1) {
    s[rt << 1].cnt = s[rt << 1 | 1].cnt = s[rt].cnt;
    s[rt << 1].ls = s[rt << 1].rs = s[rt << 1].ms = s[rt].cnt * s[rt << 1].len;
    s[rt << 1 | 1].ls = s[rt << 1 | 1].rs = s[rt << 1 | 1].ms =
        s[rt].cnt * s[rt << 1 | 1].len;
    s[rt].cnt = -1;
  }
}
void print(int rt) {
  if (s[rt].l == s[rt].r) {
    printf("%d", s[rt].ms);
    return;
  }
  pushdown(rt);
  print(rt << 1);
  print(rt << 1 | 1);
}
void upda(int L, int R, int w, int rt) {
  if (s[rt].l >= L && s[rt].r <= R) {
    s[rt].cnt = w;
    s[rt].ls = s[rt].rs = s[rt].ms = w * (s[rt].len);
    return;
  }
  int mid = (s[rt].l + s[rt].r) >> 1;
  pushdown(rt);
  if (L <= mid) upda(L, R, w, rt << 1);
  if (R > mid) upda(L, R, w, rt << 1 | 1);
  pushup(rt);
}
int query(int len, int rt) {
  if (s[rt].ms < len) return -1;
  if (s[rt].ls >= len) return s[rt].l;
  pushdown(rt);
  int mid = (s[rt].l + s[rt].r) >> 1;
  if (s[rt << 1].ms >= len)
    return query(len, rt << 1);
  else if (s[rt << 1].rs + s[rt << 1 | 1].ls >= len)
    return mid - s[rt << 1].rs + 1;
  else
    return query(len, rt << 1 | 1);
}
int main() {
  int len, n, m;
  int num;
  while (~scanf("%d %d %d", &len, &n, &m)) {
    int coun = 1;
    scanf("%d", &num);
    build(0, len + n + m - 1, 1);
    while (num--) {
      int k, h;
      scanf("%d %d", &k, &h);
      if (k == 1) {
        int lenn = h + n + m;
        int t = query(lenn, 1);
        printf("%d\n", t);
        if (t != -1) {
          int st = t + n;
          int en = t + n + h - 1;
          chu[coun].l = st;
          chu[coun].r = en;
          upda(st, en, 0, 1);
        }
      } else {
        upda(chu[h].l, chu[h].r, 1, 1);
      }
      coun++;
    }
  }
  return 0;
}
