#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
struct Union_Find_Set {
  int fa[4000005], siz[4000005], top;
  pair<int, int> stk[4000005];
  void init(int x) {
    for (int i = 1; i <= x; i++) fa[i] = i, siz[i] = 1;
  }
  int find(int x) { return fa[x] == x ? x : find(fa[x]); }
  void merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (siz[x] > siz[y]) swap(x, y);
    stk[++top] = make_pair(x, y);
    fa[x] = y;
    siz[y] += siz[x];
  }
  void del() {
    fa[stk[top].first] = stk[top].first;
    siz[stk[top].second] -= siz[stk[top].first];
    --top;
  }
} S;
int n, m, k, be[4000005], now, opt[4000005], x[4000005], y[4000005],
    tim[4000005];
struct Segment_Tree {
  vector<pair<int, int> > G[4000005];
  void modify(int l, int r, int k, int x, int y, pair<int, int> e) {
    if (l >= x && r <= y) {
      G[k].push_back(e);
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) modify(l, mid, k << 1, x, y, e);
    if (y > mid) modify(mid + 1, r, k << 1 | 1, x, y, e);
  }
  void query(int l, int r, int k) {
    int siz = G[k].size(), lst = S.top;
    for (int i = 0; i < siz; i++) S.merge(G[k][i].first, G[k][i].second);
    if (l == r) {
      if (opt[l] == 2) {
        printf("%d\n", S.siz[S.find(x[l])]);
      }
      while (S.top != lst) S.del();
      return;
    }
    int mid = (l + r) >> 1;
    query(l, mid, k << 1);
    query(mid + 1, r, k << 1 | 1);
    while (S.top != lst) S.del();
  }
} T;
int main() {
  n = read();
  m = read();
  k = read();
  S.init(n);
  for (int i = 1; i <= m; i++) {
    opt[i] = read();
    if (opt[i] == 1) x[i] = read(), y[i] = read(), tim[i] = now;
    if (opt[i] == 2) x[i] = read();
    if (opt[i] == 3) be[++now] = i;
  }
  for (int i = 1; i <= m; i++) {
    if (opt[i] == 1) {
      int E = be[tim[i] + k];
      if (!E) E = m;
      T.modify(1, m, 1, i, E, make_pair(x[i], y[i]));
    }
  }
  T.query(1, m, 1);
}
