Problem: Serge, the chef of the famous restaurant "Salt, Pepper & Garlic" is trying to obtain his first Michelin star. He has been informed that a secret expert plans to visit his restaurant this evening.

Even though the expert's name hasn't been disclosed, Serge is certain he knows which dish from the menu will be ordered as well as what the taste preferences of the expert are. Namely, the expert requires an extremely precise proportion of salt, pepper and garlic powder in his dish.

Serge keeps a set of bottles with mixtures of salt, pepper and garlic powder on a special shelf in the kitchen. For each bottle, he knows the exact amount of each of the ingredients in kilograms. Serge can combine any number of bottled mixtures (or just use one of them directly) to get a mixture of particular proportions needed for a certain dish.

Luckily, the absolute amount of a mixture that needs to be added to a dish is so small that you can assume that the amounts in the bottles will always be sufficient. However, the numeric values describing the proportions may be quite large.

Serge would like to know whether it is possible to obtain the expert's favourite mixture from the available bottles, and if so—what is the smallest possible number of bottles needed to achieve that.

Furthermore, the set of bottles on the shelf may change over time as Serge receives new ones or lends his to other chefs. So he would like to answer this question after each such change.

For example, assume that expert's favorite mixture is 1:1:1 and there are three bottles of mixtures on the shelf:

$$$ \begin{array}{cccc} \hline Mixture & Salt & Pepper & Garlic powder \\\ \hline 1 & 10 & 20 & 30 \\\ 2 & 300 & 200 & 100 \\\ 3 & 12 & 15 & 27 \\\ \hline \end{array} $$$ Amount of ingredient in the bottle, kg 

To obtain the desired mixture it is enough to use an equivalent amount of mixtures from bottles 1 and 2. If bottle 2 is removed, then it is no longer possible to obtain it.

Write a program that helps Serge to solve this task!

Input

The first row contains three non-negative integers S_f, P_f and G_f (0 ≤ S_f, P_f, G_f; 0 < S_f+P_f+G_f ≤ 10^6) describing the amount of salt, pepper and garlic powder in the expert's favourite mixture. For any real α>0, (α{S_f}, α{P_f}, α{G_f}) also is an expert's favourite mixture.

In the second row, there is a positive integer N (number of changes on the shelf, N ≤ 100 000). You should assume that initially the shelf is empty.

Each of the next N rows describes a single change on the shelf: 

  * If a new bottle is added, the row contains capital letter A followed by three non-negative integers S_i, P_i and G_i (0 ≤ S_i, P_i, G_i; 0 < S_i+P_i+G_i ≤ 10^6) describing the amount of salt, pepper and garlic powder in the added bottle. Added bottles are numbered consecutively by unique integers starting from 1, that is, the i-th bottle corresponds to the i-th added bottle in the input data. 
  * If a particular bottle is removed from the shelf, the row contains capital letter R followed by the integer—the bottle number r_i. All values r_i in the removals are unique, r_i never exceeds total number of bottles added thus far. 

Output

Output N rows. The j-th row (1 ≤ j ≤ N) should contain the number x_j, the smallest number of bottles needed to prepare a mixture with the expert's favourite proportions of salt, pepper and garlic powder using the bottles available after the first j changes on the shelf, or 0 if it is not possible.

Scoring

Subtasks: 

  1. (13 points) N ≤ 50, 0 < S_i+P_i+G_i ≤ 10^2 
  2. (17 points) N ≤ 500, 0 < S_i+P_i+G_i ≤ 10^3 
  3. (30 points) N ≤ 5000, 0 < S_i+P_i+G_i ≤ 10^4 
  4. (40 points) No further constraints 

Example

Input


1 2 3
6
A 5 6 7
A 3 10 17
R 1
A 15 18 21
A 5 10 15
R 3


Output


0
2
0
2
1
1

Note

Pay attention that in the example, bottles 1 and 3 contain the same proportions of salt, pepper and garlic powder.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
std::mt19937 rnd(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXQ = 100000;
struct Mix {
  int a, b, c;
};
struct P {
  int x, y, den;
  P() {}
  P(int _x, int _y, int _den) : x(_x), y(_y), den(_den) {
    int g = gcd(gcd(x, y), den);
    x /= g, y /= g, den /= g;
  }
};
bool operator==(const P &a, const P &b) {
  return a.x == b.x && a.y == b.y && a.den == b.den;
}
Mix want;
int nq;
char qtype[MAXQ];
int qadd[MAXQ];
int qrem[MAXQ];
int qans[MAXQ];
Mix have[MAXQ];
int nhave;
P pwant;
P phave[MAXQ];
int o[2 * MAXQ], no;
int dir[MAXQ];
int pos[MAXQ], posinv[MAXQ], npos;
int side(const P &a, const P &b, const P &c) {
  long long lhs = (long long)b.x * c.y * a.den - (long long)a.y * b.x * c.den -
                  (long long)a.x * c.y * b.den;
  long long rhs = (long long)b.y * c.x * a.den - (long long)a.x * b.y * c.den -
                  (long long)a.y * c.x * b.den;
  return lhs != rhs ? lhs > rhs ? +1 : -1 : 0;
}
int cmpang(const P &orig, const P &a, bool inva, const P &b, bool invb) {
  bool apos = (long long)a.y * orig.den > (long long)orig.y * a.den ||
              (long long)a.y * orig.den == (long long)orig.y * a.den &&
                  (long long)a.x * orig.den > (long long)orig.x * a.den;
  if (inva) apos = !apos;
  bool bpos = (long long)b.y * orig.den > (long long)orig.y * b.den ||
              (long long)b.y * orig.den == (long long)orig.y * b.den &&
                  (long long)b.x * orig.den > (long long)orig.x * b.den;
  if (invb) bpos = !bpos;
  if (apos != bpos) return apos ? -1 : +1;
  int ret = side(orig, a, b);
  if (inva) ret *= -1;
  if (invb) ret *= -1;
  return ret;
}
map<int, int> alive;
int cntwant, cntoppo, cntlarge;
void add(int idx) {
  if (pos[idx] == -1) {
    ++cntwant;
    return;
  }
  if (alive.count(pos[idx]) == 0 && alive.count(posinv[idx]) > 0) ++cntoppo;
  if (alive.count(pos[idx]) == 0) {
    alive[pos[idx]] = 1;
    if (((int)(alive).size()) >= 2) {
      auto it = alive.find(pos[idx]);
      int ppos =
          it == alive.begin() ? prev(alive.end())->first : prev(it)->first;
      int cpos = pos[idx];
      int npos =
          next(it) == alive.end() ? alive.begin()->first : next(it)->first;
      assert(dir[ppos] != -1 && dir[cpos] != -1 && dir[npos] != -1);
      P pp = phave[dir[ppos]], cp = phave[dir[cpos]], np = phave[dir[npos]];
      if (((int)(alive).size()) >= 3 && side(pwant, pp, np) < 0) --cntlarge;
      if (side(pwant, pp, cp) < 0) ++cntlarge;
      if (side(pwant, cp, np) < 0) ++cntlarge;
    }
  } else {
    ++alive[pos[idx]];
  }
}
void rem(int idx) {
  if (pos[idx] == -1) {
    --cntwant;
    return;
  }
  assert(alive.count(pos[idx]));
  if (alive[pos[idx]] >= 2) {
    --alive[pos[idx]];
    return;
  }
  if (alive.count(posinv[idx]) > 0) --cntoppo;
  auto it = alive.find(pos[idx]);
  if (((int)(alive).size()) >= 2) {
    int ppos = it == alive.begin() ? prev(alive.end())->first : prev(it)->first;
    int cpos = pos[idx];
    int npos = next(it) == alive.end() ? alive.begin()->first : next(it)->first;
    assert(dir[ppos] != -1 && dir[cpos] != -1 && dir[npos] != -1);
    P pp = phave[dir[ppos]], cp = phave[dir[cpos]], np = phave[dir[npos]];
    if (((int)(alive).size()) >= 3 && side(pwant, pp, np) < 0) ++cntlarge;
    if (side(pwant, pp, cp) < 0) --cntlarge;
    if (side(pwant, cp, np) < 0) --cntlarge;
  }
  alive.erase(it);
}
int calc() {
  if (cntwant > 0) return 1;
  if (cntoppo > 0) return 2;
  if (((int)(alive).size()) >= 2 && cntlarge == 0) return 3;
  return 0;
}
void solve() {
  pwant = P(want.a, want.b, want.a + want.b + want.c);
  for (int i = (0); i < (nhave); ++i)
    phave[i] = P(have[i].a, have[i].b, have[i].a + have[i].b + have[i].c);
  no = 0;
  for (int i = (0); i < (nhave); ++i)
    if (!(phave[i] == pwant)) o[no++] = 2 * i + 0, o[no++] = 2 * i + 1;
  sort(o, o + no, [&](const int &a, const int &b) {
    return cmpang(pwant, phave[a / 2], a % 2 == 1, phave[b / 2], b % 2 == 1) >
           0;
  });
  npos = 0;
  for (int i = (0); i < (nhave); ++i) pos[i] = -1, posinv[i] = -1;
  for (int i = (0); i < (no); ++i) {
    if (i == 0 || cmpang(pwant, phave[o[i - 1] / 2], o[i - 1] % 2 == 1,
                         phave[o[i] / 2], o[i] % 2 == 1) != 0)
      dir[npos++] = -1;
    if (o[i] % 2 == 0 && dir[npos - 1] == -1) dir[npos - 1] = o[i] / 2;
    if (o[i] % 2 == 0)
      pos[o[i] / 2] = npos - 1;
    else
      posinv[o[i] / 2] = npos - 1;
  }
  alive.clear(), cntwant = 0, cntoppo = 0, cntlarge = 0;
  for (int i = (0); i < (nq); ++i) {
    if (qtype[i] == 'A') add(qadd[i]);
    if (qtype[i] == 'R') rem(qrem[i]);
    qans[i] = calc();
  }
}
void run() {
  scanf("%d%d%d", &want.a, &want.b, &want.c);
  scanf("%d", &nq);
  nhave = 0;
  for (int i = (0); i < (nq); ++i) {
    scanf(" %c", &qtype[i]);
    if (qtype[i] == 'A')
      scanf("%d%d%d", &have[nhave].a, &have[nhave].b, &have[nhave].c),
          qadd[i] = nhave++;
    if (qtype[i] == 'R') scanf("%d", &qrem[i]), --qrem[i];
  }
  solve();
  for (int i = (0); i < (nq); ++i) printf("%d\n", qans[i]);
}
int main() {
  run();
  return 0;
}