/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 * Date: 2013.09.23
 *
 * Status: TL
 */

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

using namespace std;

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

#ifdef DEBUG
#  define err(...) fprintf(stderr, __VA_ARGS__)
#else
#  define err(...) 
#endif

const int N = 1000;

int n, q;
unsigned A, B, koef[N][N];
bitset<N> c[N];
int cc, u[N][N];

inline void dfs( int v, int *u )
{
  u[v] = cc;
  forn(i, n)
    if (c[v][i])
    {
      assert(u[i] != cc); // no cycles
      if (u[i] < cc)
        dfs(i, u);
    }
  u[v] = cc + 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;
    assert(scanf(" %c %c%d%d", &com, &type, &v, &k) == 4 && 1 <= v && v <= n), v--;
    err("%c %c %d %d\n", com, type, v, k);
    #ifdef DEBUG
    forn(i, n)
      forn(j, n)
        err("%d%s", (int)c[i][j], j == n - 1 ? "\n" : "");
    #endif
    com = (com == '+' ? 1 : 0);
    while (k--)
    {
      assert(scanf("%d", &a) == 1 && 1 <= a && a <= n), a--;
      assert(a != v); // no loops
      err("a = %d [%d -> %d]\n", a, (int)c[a][v], (int)com);
      if (type == 'o') 
        assert(c[v][a] != com), c[v][a] = com; // edge changed
      else
        assert(c[a][v] != com), c[a][v] = com;
    }

    unsigned sum = 0;
    forn(v, n)
    {
      cc += 2, dfs(v, u[v]);
      forn(i, n)
        if (v != i && u[v][i] > cc)
          sum += koef[v][i];
    }
    printf("%u\n", sum);
  }
  return 0;
}
