#include <bits/stdc++.h>
struct {
  int l, r;
} qur[100];
int mx[400005], ls[400005], rs[400005], att[400005];
void debug(int idx, int s, int e) {
  printf("idx=%d,s=%d,e=%d,mx=%d,ls=%d,rs=%d\n", idx, s, e, mx[idx], ls[idx],
         rs[idx]);
  if (s != e) {
    int mid = (s + e) >> 1;
    debug(idx << 1, s, mid);
    debug(idx << 1 | 1, mid + 1, e);
  }
}
void build(int idx, int s, int e) {
  if (s != e) {
    int mid = (s + e) >> 1;
    build(idx << 1, s, mid);
    build(idx << 1 | 1, mid + 1, e);
  }
  mx[idx] = ls[idx] = rs[idx] = e - s + 1;
  att[idx] = -1;
}
void update(int idx, int s, int e, int l, int r, int val) {
  if (l == s && e == r) {
    att[idx] = val;
    mx[idx] = ls[idx] = rs[idx] = (e - s + 1) * val;
    return;
  }
  int mid = (s + e) >> 1;
  if (att[idx] != -1) {
    mx[idx << 1] = ls[idx << 1] = rs[idx << 1] = (mid - s + 1) * att[idx];
    mx[idx << 1 | 1] = ls[idx << 1 | 1] = rs[idx << 1 | 1] =
        (e - mid) * att[idx];
    att[idx << 1] = att[idx << 1 | 1] = att[idx];
    att[idx] = -1;
  }
  if (r <= mid)
    update(idx << 1, s, mid, l, r, val);
  else if (l > mid)
    update(idx << 1 | 1, mid + 1, e, l, r, val);
  else {
    update(idx << 1, s, mid, l, mid, val);
    update(idx << 1 | 1, mid + 1, e, mid + 1, r, val);
  }
  ls[idx] = ls[idx << 1];
  rs[idx] = rs[idx << 1 | 1];
  mx[idx] = (mx[idx << 1] > mx[idx << 1 | 1] ? mx[idx << 1] : mx[idx << 1 | 1]);
  if (ls[idx] == mid - s + 1) ls[idx] += ls[idx << 1 | 1];
  if (rs[idx] == e - mid) rs[idx] += rs[idx << 1];
  mx[idx] = (rs[idx << 1] + ls[idx << 1 | 1] > mx[idx]
                 ? rs[idx << 1] + ls[idx << 1 | 1]
                 : mx[idx]);
}
int query(int idx, int s, int e, int val) {
  int mid = (s + e) >> 1;
  if (att[idx] != -1) {
    mx[idx << 1] = ls[idx << 1] = rs[idx << 1] = (mid - s + 1) * att[idx];
    mx[idx << 1 | 1] = ls[idx << 1 | 1] = rs[idx << 1 | 1] =
        (e - mid) * att[idx];
    att[idx << 1] = att[idx << 1 | 1] = att[idx];
    att[idx] = -1;
  }
  if (mx[idx << 1] >= val)
    return query(idx << 1, s, mid, val);
  else if (rs[idx << 1] + ls[idx << 1 | 1] >= val)
    return mid - rs[idx << 1] + 1;
  else if (mx[idx << 1 | 1] >= val)
    return query(idx << 1 | 1, mid + 1, e, val);
  else
    return -1;
}
int main() {
  int n, b, f, q, i, type, val, ans;
  while (~scanf("%d%d%d%d", &n, &b, &f, &q)) {
    n += b + f - 1;
    build(1, 0, n);
    for (i = 1; i <= q; i++) {
      scanf("%d%d", &type, &val);
      if (type == 1) {
        ans = query(1, 0, n, val + b + f);
        printf("%d\n", ans);
        if (ans == -1) continue;
        qur[i].l = ans + b;
        qur[i].r = ans + b + val - 1;
        update(1, 0, n, qur[i].l, qur[i].r, 0);
      } else
        update(1, 0, n, qur[val].l, qur[val].r, 1);
    }
  }
}
