#include <bits/stdc++.h>
using namespace std;

int n;
vector<tuple<int, int, int>> order;
vector<tuple<int, int, int, int>> bestans;

void input() {
    cin >> n;
    order.resize(n);
    for (auto& [x, y, r] : order) cin >> x >> y >> r;
}

void init() {
    bestans.resize(n);
}

void simulate() {
    for (int i = 0; i < n; ++i) {
        auto [x, y, r] = order[i];
        auto& [a, b, c, d] = bestans[i];
        a = x, c = x + 1;
        b = y, d = y + 1;
    }
}

void output() {
    for (auto [a, b, c, d] : bestans) {
        cout << a << ' ' << b << ' ' << c << ' ' << d << '\n';
    }
}

int main() {
    input();
    init();
    simulate();
    output();
}
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, Q;
  cin >> N >> Q;
  vector<int> C(N);
  for (int i = 0; i < N; i++){
    cin >> C[i];
  }
  vector<map<int, int>> mp(N);
  vector<int> p(N);
  vector<vector<int>> g(N);
  for (int i = 0; i < N; i++){
    p[i] = i;
    mp[i][C[i]] = 1;
    g[i].push_back(i);
  }
  for (int i = 0; i < Q; i++){
    int t;
    cin >> t;
    if (t == 1){
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      a = p[a];
      b = p[b];
      if (a == b){
        continue;
      }
      if (g[a].size() < g[b].size()){
        swap(a, b);
      }
      for (int x : g[b]){
        g[a].push_back(x);
        p[x] = a;
      }
      g[b].clear();
      for (auto P : mp[b]){
        mp[a][P.first] += P.second;
      }
      mp[b].clear();
    }
    if (t == 2){
      int x, y;
      cin >> x >> y;
      x--;
      cout << mp[p[x]][y] << endl;
    }
  }
}