#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
const int inf = 1e18;
int f[N], num[N], rak[N];
vector<int> ans;
int fid(int x) {
  if (x == f[x]) return f[x];
  return fid(f[x]);
}
void join(int x, int y, stack<pair<int *, int>> &stk) {
  x = fid(x), y = fid(y);
  if (x == y) return;
  if (rak[x] <= rak[y]) {
    stk.push({f + x, f[x]});
    stk.push({num + y, num[y]});
    f[x] = y;
    num[y] += num[x];
    if (rak[x] == rak[y]) {
      stk.push({rak + y, rak[y]});
      rak[y]++;
    }
  } else {
    stk.push({f + y, f[y]});
    stk.push({num + x, num[x]});
    f[y] = x;
    num[x] += num[y];
  }
}
struct node {
  vector<pair<int, int>> v;
} tree[N * 4];
void update(int l, int r, int rt, int L, int R, pair<int, int> p) {
  if (l >= L && r <= R) {
    tree[rt].v.push_back(p);
    return;
  }
  int mid = (l + r) / 2;
  if (mid >= L) update(l, mid, rt * 2, L, R, p);
  if (mid < R) update(mid + 1, r, rt * 2 + 1, L, R, p);
}
int vis[N];
void dfs(int l, int r, int rt) {
  stack<pair<int *, int>> stk;
  for (int i = 0; i < tree[rt].v.size(); i++) {
    join(tree[rt].v[i].first, tree[rt].v[i].second, stk);
  }
  if (l != r) {
    int mid = (l + r) / 2;
    dfs(l, mid, rt * 2);
    dfs(mid + 1, r, rt * 2 + 1);
  } else {
    if (vis[l]) {
      ans.push_back(num[fid(vis[l])]);
    }
  }
  while (stk.size()) {
    *stk.top().first = stk.top().second;
    stk.pop();
  }
}
vector<int> ddddd;
struct ojbk {
  int x, y, day, id;
};
vector<ojbk> vvv;
signed main() {
  int n, q, k;
  cin >> n >> q >> k;
  int day = 1;
  for (int i = 1; i <= n; i++) f[i] = i, rak[i] = 1, num[i] = 1;
  for (int i = 1; i <= q; i++) {
    int ch;
    cin >> ch;
    if (ch == 3) {
      ddddd.push_back(i);
      day++;
    } else if (ch == 2) {
      int x;
      cin >> x;
      vis[i] = x;
    } else {
      int a1, a2;
      cin >> a1 >> a2;
      vvv.push_back({a1, a2, day, i});
    }
  }
  for (int i = 0; i < vvv.size(); i++) {
    int a1 = vvv[i].x;
    int a2 = vvv[i].y;
    if (vvv[i].day + k - 1 > ddddd.size()) {
      update(1, q, 1, vvv[i].id, q, {a1, a2});
    } else {
      update(1, q, 1, vvv[i].id, ddddd[vvv[i].day + k - 2], {a1, a2});
    }
  }
  dfs(1, q, 1);
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
}
