#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 500500;
bool ok[N];
vector<int> g[N];
int u[N], sz[N], nw_sz[N];
int n, q, k, tp[N], x[N], y[N], fin[N], ans[N];
struct edge {
  int x, y, l, r;
};
void dfs(int v, int col) {
  u[v] = col;
  nw_sz[col] += sz[v];
  for (auto to : g[v])
    if (!u[to]) dfs(to, col);
}
long long A, B, C;
bool flag;
void solve(int l, int r, int tot, const vector<edge> &e, const vector<int> &qr,
           const vector<int> &comp) {
  if (qr.empty()) return;
  if (e.empty()) {
    if (!flag)
      for (auto i : qr) printf("%d\n", comp[x[i] - 1]);
    return;
  }
  A += (int)e.size();
  B += (int)qr.size();
  C += (int)comp.size();
  for (int i = 1; i <= tot; i++) {
    g[i].clear();
    u[i] = 0;
    sz[i] = comp[i - 1];
    nw_sz[i] = 0;
  }
  vector<edge> nw_e;
  for (auto i : e) {
    if (i.x == i.y) continue;
    if (i.l <= l && r <= i.r) {
      g[i.x].push_back(i.y);
      g[i.y].push_back(i.x);
      continue;
    }
    if (!(i.r < l || r < i.l)) nw_e.push_back(i);
  }
  int nw_tot = 0;
  vector<int> nw_comp;
  for (int i = 1; i <= tot; i++) {
    if (u[i]) continue;
    nw_tot++;
    dfs(i, nw_tot);
  }
  for (auto i : qr) x[i] = u[x[i]];
  if (l == r) {
    if (!flag && tp[r] == 2) ans[r] = nw_sz[x[qr.back()]];
    return;
  }
  for (int i = 1; i <= nw_tot; i++) ok[i] = 0;
  for (auto &i : nw_e) {
    i.x = u[i.x];
    i.y = u[i.y];
    if (i.x != i.y) ok[i.x] = ok[i.y] = 1;
  }
  int mid = (l + r) >> 1;
  for (auto i : qr) {
    if (!ok[x[i]]) ans[i] = nw_sz[x[i]];
  }
  vector<int> qr_L, qr_R;
  for (auto i : qr) {
    if (!ok[x[i]]) continue;
    if (i <= mid)
      qr_L.push_back(i);
    else
      qr_R.push_back(i);
  }
  for (int i = 1; i <= nw_tot; i++) {
    if (ok[i]) {
      nw_comp.push_back(nw_sz[i]);
      u[i] = (int)nw_comp.size();
    }
  }
  for (auto &i : nw_e) {
    i.x = u[i.x];
    i.y = u[i.y];
  }
  for (auto i : qr) x[i] = u[x[i]];
  nw_tot = (int)nw_comp.size();
  solve(l, mid, nw_tot, nw_e, qr_L, nw_comp);
  solve(mid + 1, r, nw_tot, nw_e, qr_R, nw_comp);
}
int main() {
  scanf("%d %d %d", &n, &q, &k);
  int day = 1;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &tp[i]);
    if (tp[i] == 1)
      scanf("%d %d", &x[i], &y[i]);
    else if (tp[i] == 2)
      scanf("%d", &x[i]);
    else {
      fin[day] = i;
      day++;
    }
  }
  if (!fin[day]) fin[day] = q;
  int last = day;
  day = 1;
  vector<int> qr, comp;
  vector<edge> e;
  for (int i = 1; i <= q; i++) {
    if (tp[i] == 1)
      e.push_back({x[i], y[i], i, fin[min(last, day + k - 1)]});
    else if (tp[i] == 2)
      qr.push_back(i);
    else
      day++;
  }
  for (int i = 1; i <= n; i++) comp.push_back(1);
  solve(1, q, n, e, qr, comp);
  for (int i = 1; i <= q; i++)
    if (!flag && tp[i] == 2) printf("%d\n", ans[i]);
  if (flag) printf("%lld %lld %lld\n", A, B, C);
  return 0;
}
