/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 * Date: 2013.10.04
 *
 * Status: Accepted, Time = 1.39
 */

#include <cstdio>
#include <cassert>
#include <cstring>
#include <bitset>

using namespace std;

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

const int N = 400;
const int E = N * N / 2;

int n, q;
unsigned A, B, koef[N][N];
char c[N][N];
int e, head[N], next[E], to[E];
int cc, u[N];
bitset <N> is[N];

inline void calc( int v )
{
  u[v] = cc;
  for (int e = head[v]; e; e = next[e])
  {
    int x = to[e];
    if (u[x] != cc)
      calc(x);
    is[v] |= is[x];
  }
  is[v][v] = 1;
}

int main()
{
  #define NAME "reachability"
  assert(freopen(NAME ".in", "r", stdin));
  assert(freopen(NAME ".out", "w", stdout));

  assert(scanf("%d%d%u%u", &n, &q, &A, &B) == 4 && n <= N); // no overflow
  koef[0][0] = 1;
  forn(i, n - 1)
    koef[i + 1][0] = koef[i][0] * A;
  forn(i, n)
    forn(j, n - 1)
      koef[i][j + 1] = koef[i][j] * B;

  while (q--)
  {
    char com, type;
    int v, k, a;
    scanf(" %c %c%d%d", &com, &type, &v, &k), v--;
    com = (com == '+' ? 1 : 0);
    while (k--)
    {
      scanf("%d", &a), a--;
      (type == 'o' ? c[v][a] : c[a][v]) = com;
    }

    e = 1;
    memset(head, 0, sizeof(head));
    forn(i, n)
      forn(j, n)
        if (c[i][j])
          next[e] = head[i], to[e] = j, head[i] = e++;

    unsigned sum = 0;
    cc++;
    forn(v, n)
      is[v].reset();
    forn(v, n)
      if (u[v] != cc)
        calc(v);
    forn(i, n)
      forn(j, n)
        if (i != j && is[i][j])
          sum += koef[i][j];
    printf("%u\n", sum);
  }
  return 0;
}
