#define NOFOOTER

#include "my_testlib.h"

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

const int N = 400;
const int Q = 800;
const int X = (int)1e9;

int n, q, g[N][N];
int cc, u[N];

void go( int v )
{
  u[v] = cc;
  forn(i, n)
    if (g[v][i])
    {
      ensure(u[i] != cc);
      if (u[i] < cc)
        go(i);
    }
  u[v] = cc + 1;
}

int main(int, char *[])
{
  registerValidation();

  n = inf.readInt(1, N);
  inf.readSpace();
  q = inf.readInt(1, Q);
  inf.readSpace();
  inf.readInt(1, X); // A
  inf.readSpace();
  inf.readInt(1, X); // B
  inf.readEoln();

  while (q--)
  {
    //fprintf(stderr, "[%d]", q);
    char ch = inf.readChar();
    ensure(ch == '+' || ch == '-');
    inf.readSpace();
    int val = (ch == '+');
    char type = inf.readChar();
    ensure(type == 'i' || type == 'o');
    inf.readSpace();
    int v = inf.readInt(1, n) - 1;
    inf.readSpace();
    int k = inf.readInt(1, n);
    forn(i, k)
    {
      inf.readSpace();
      int a = inf.readInt(1, n) - 1;
      ensure(a != v); // no loops
      int &r = (type == 'i' ? g[a][v] : g[v][a]);
      ensure(r != val);
      r = val;
    }
    cc += 2;
    forn(i, n)
      if (u[i] < cc)
        go(i);
    inf.readEoln();
  }

  inf.readEof();
  return 0;
}
