#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int ans[N], idx[N];
vector<pair<int, int> > edges[N << 2], query[N];
void update(int v, int l, int r, int L, int R, int x, int y) {
  if (l > R || r < L) return;
  if (l >= L && r <= R) {
    edges[v].push_back(make_pair(x, y));
    return;
  }
  int mid = (l + r) / 2;
  update(v * 2, l, mid, L, R, x, y);
  update(v * 2 + 1, mid + 1, r, L, R, x, y);
}
struct DSU {
  vector<int> p, sz;
  stack<int> stk;
  DSU(int n) {
    p.resize(n + 1);
    sz.resize(n + 1, 1);
    for (int i = 1; i <= n; i++) p[i] = i;
  }
  int find(int x) { return (p[x] == x) ? p[x] : find(p[x]); }
  int merge(int x, int y) {
    if ((x = find(x)) ^ (y = find(y))) {
      if (sz[x] > sz[y]) swap(x, y);
      p[x] = y;
      sz[y] += sz[x];
      stk.push(x);
    }
    return 0;
  }
  void roll_back(int t) {
    while (stk.size() > t) {
      int x = stk.top();
      stk.pop();
      sz[p[x]] -= sz[x];
      p[x] = x;
    }
  }
};
void build(int v, int l, int r, DSU &d) {
  int tm = d.stk.size();
  for (auto e : edges[v]) {
    d.merge(e.first, e.second);
  }
  if (l == r) {
    for (auto kk : query[l]) ans[kk.second] = d.sz[d.find(kk.first)];
  } else {
    int mid = (l + r) / 2;
    build(v * 2, l, mid, d);
    build(v * 2 + 1, mid + 1, r, d);
  }
  d.roll_back(tm);
}
int tt[N], xx[N], yy[N], dd[N];
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q, k, day = 1, c = 0;
  cin >> n >> q >> k;
  DSU d(n);
  fill(begin(idx), end(idx), q + 1);
  idx[1] = 1;
  for (int i = 1; i <= q; i++) {
    int typ;
    cin >> typ;
    if (typ == 1) {
      tt[i] = 1;
      cin >> xx[i] >> yy[i];
      dd[i] = day;
    } else if (typ == 2) {
      int z;
      cin >> z;
      query[i].push_back(make_pair(z, ++c));
    } else {
      day++;
      idx[day] = i + 1;
    }
  }
  for (int i = 1; i <= q; i++) {
    if (tt[i] == 1) {
      update(1, 1, q, i, idx[dd[i] + k] - 1, xx[i], yy[i]);
    }
  }
  build(1, 1, q, d);
  for (int i = 1; i <= c; i++) cout << ans[i] << "\n";
}
