#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair PII; #define fi first #define se second #define MP make_pair int read() { int v = 0, f = 1; char c = getchar(); while (c < 48 || 57 < c) {if (c == '-') f = -1; c = getchar();} while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar(); return v * f; } const int N = 1000000; int q, cnt; char op[10]; char ch[32]; int now, n; int flg[N], A[100]; struct EG { int a, b, c; } eg[N]; int head[N], en; void SetEdge(int u, int v, int w) { eg[++en] = (EG) {v, head[u], w}; head[u] = en; } int find(int u, int c) { for (int e = head[u]; e; e = eg[e].b) if (eg[e].c == c) return eg[e].a; return 0; } int main() { scanf("%d", &q); cnt = 1; while (q--) { scanf("%s", op); memset(ch, 0, sizeof ch); scanf("%s", ch + 1); n = strlen(ch + 1); if (op[0] == 'i') { now = 1; for (int i = 1; i <= n; i++) { if (find(now, ch[i] - 'a') == 0) SetEdge(now, ++cnt, ch[i] - 'a'); now = find(now, ch[i] - 'a'); if (!flg[now]) for (int e = head[now]; e; e = eg[e].b) flg[eg[e].a] = 0; flg[now] = 1; } } if (op[0] == 'd') { now = 1; A[0] = 0; for (int i = 1; i <= n; i++) { now = find(now, ch[i] - 'a'); A[++A[0]] = now; if (!flg[now]) for (int e = head[now]; e; e = eg[e].b) flg[eg[e].a] = 0; } flg[now] = 0; if (now > 0) { for (int i = A[0] - 1; i >= 1; i--) { bool fg = 0; for (int e = head[A[i]]; e; e = eg[e].b) { int v = eg[e].a; if (flg[v]) fg = 1; } flg[A[i]] = fg; } } } if (op[0] == 's') { now = 1; for (int i = 1; i <= n; i++) { now = find(now, ch[i] - 'a'); if (!flg[now]) for (int e = head[now]; e; e = eg[e].b) flg[eg[e].a] = 0; } if (flg[now]) puts("Yes"); else puts("No"); } } }