#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
const array<ll, 3> def = {0, 0, 0};
array<ll, 3> basis[3];
array<ll, 3> cont[3];
int sz;
void init() {
sz = 0;
for (int i = 0; i < 3; ++i) {
basis[i] = def;
}
}
array<ll, 3> add(array<ll, 3> &a, array<ll, 3> &b) {
return {a[0]+b[0], a[1]+b[1], a[2]+b[2]};
}
array<ll, 3> mul(array<ll, 3> &a, ll k) {
return {a[0]*k, a[1]*k, a[2]*k};
}
void insert(array<ll, 3> a) {
array<ll, 3> c = def;
c[sz] = 1;
for (int i = 0; i < 3; ++i) {
if (a[i] == 0)
continue;
if (basis[i] == def) {
basis[i] = a;
cont[i] = c;
++sz;
return;
}
array<ll, 3> b = basis[i];
array<ll, 3> cb = cont[i];
if (a[i] < 0) {
a = mul(a, -1);
c = mul(c, -1);
}
if (b[i] < 0) {
b = mul(b, -1);
cb = mul(cb, -1);
}
ll g = gcd(a[i], b[i]);
ll ma = b[i]/g;
ll mb = a[i]/g;
a = mul(a, ma);
c = mul(c, ma);
b = mul(b, -mb);
cb = mul(cb, -mb);
a = add(a, b);
c = add(c, cb);
}
}
array<ll, 3> build(array<ll, 3> a) {
array<ll, 3> c = def;
for (int i = 0; i < 3; ++i) {
if (a[i] == 0)
continue;
if (basis[i] == def)
return def;
array<ll, 3> b = basis[i];
array<ll, 3> cb = cont[i];
if (a[i] < 0) {
a = mul(a, -1);
c = mul(c, -1);
}
if (b[i] < 0) {
b = mul(b, -1);
cb = mul(cb, -1);
}
ll g = gcd(a[i], b[i]);
ll ma = b[i]/g;
ll mb = a[i]/g;
a = mul(a, ma);
c = mul(c, ma);
b = mul(b, -mb);
cb = mul(cb, -mb);
a = add(a, b);
c = add(c, cb);
}
return c;
}
void solve() {
array<ll, 3> goal;
cin >> goal[0] >> goal[1] >> goal[2];
int n;
cin >> n;
vector<array<ll, 3>> v(n, def);
int idx = 0;
for (int i = 0; i < n; ++i) {
char op;
cin >> op;
if (op == 'A') {
cin >> v[idx][0] >> v[idx][1] >> v[idx][2];
idx++;
} else {
int id;
cin >> id;
v[id-1] = def;
}
int ans = 4;
for (int a = 0; a < idx; ++a) if (v[a] != def) {
for (int b = a+1; b < idx; ++b) if (v[b] != def) {
for (int c = b+1; c < idx; ++c) if (v[c] != def) {
init();
insert(v[a]);
insert(v[b]);
insert(v[c]);
array<ll, 3> ans = build(goal);
if (ans == def)
continue;
bool pos = 0, neg = 0;
for (int i = 0; i < 3; ++i) {
if (ans[i] > 0)
pos = 1;
else if (ans[i] < 0)
neg = 1;
}
if (pos ^ neg)
ans = min(ans, sz);
}
}
}
cout << ans%4;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}