P1001

#include <bits/stdc++.h>

typedef std::pair<int, int> PII;
const int N = 100010;
int q, inpo, inpx, inpu, inpv, inps;
std::set<int> pts;
int ptsize;
std::vector<PII> eds;
std::vector<int> query;
bool tag[N];
std::vector<int> adj[N];
int deg[N];

int main(void) {
    scanf("%d", &q);
    while (q --) {
        scanf("%d", &inpo);
        if (inpo == 1) {
            scanf("%d", &inpx);
            if (pts.find(inpx) == pts.end()) {
                ++ ptsize;
                pts.insert(inpx);
            }
            printf("%d\n", ptsize);
        } else if (inpo == 2) {
            scanf("%d%d", &inpu, &inpv);
            if (pts.find(inpu) == pts.end() || pts.find(inpv) == pts.end()) {
                continue;
            }
            adj[inpu].push_back(inpv);
            adj[inpv].push_back(inpu);
            ++ deg[inpu];
            ++ deg[inpv];
            eds.push_back(std::make_pair(inpu, inpv));
        } else if (inpo == 3) {
            scanf("%d", &inpx);
            printf("%d\n", deg[inpx]);
        } else if (inpo == 4) {
            scanf("%d", &inps);
            query.resize(inps);
            for (int i = 0; i < inps; ++ i) {
                scanf("%d", &query[i]);
                tag[query[i]] = true;
            }
            int ans = 0;
            for (int i = 0; i < inps; ++ i) {
                for (int j = 0, l = adj[query[i]].size(); j < l; ++ j) {
                    if (tag[adj[query[i]][j]]) {
                        ++ ans;
                    }
                }
            }
            ans >>= 1;
            printf("%d\n", ans);
            for (int i = 0; i < inps; ++ i) {
                tag[query[i]] = false;
            }
        } else if (inpo == 5) {
            int ans = 0;
            scanf("%d", &inps);
            for (int i = 0; i < inps; ++ i) {
                scanf("%d", &inpx);
                -- inpx;
                if (!tag[eds[inpx].first]) {
                    ++ ans;
                    tag[eds[inpx].first] = true;
                }
                if (!tag[eds[inpx].second]) {
                    ++ ans;
                    tag[eds[inpx].second] = true;
                }
            }
            printf("%d\n", ans);
            for (auto it = pts.begin(); it != pts.end(); ++ it) {
                tag[*it] = false;
            }
        }
    }

    return 0;
}