#include <bits/stdc++.h>
const int N = 1e5;
#define ll long long
using namespace std;
int n, m;
int a[N+3];
vector<map<int, int>> v(N+3);
int parent[N+3], sz[N+3];
void make(){
for(int i=1;i<=n;i++){
v[i][a[i]] = 1;
parent[i] = i;
sz[i] = 1;
}
}
int find(int v){
if(v == parent[v])return v;
int res = find(parent[v]);
parent[v] = res;
return res;
}
void Union(int a, int b){
a = find(a);
b = find(b);
if(a != b){
if(sz[a] < sz[b])swap(a, b);
parent[b] = a;
sz[a] += sz[b];
for(auto res : v[b])v[a][res.first] += res.second;
v[b].clear();
}
}
void query(int a, int b){
a = find(a);
if(v[a].find(b) != v[a].end())cout<<v[a][b]<<"\n";
else cout<<0<<"\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
make();
while(m--){
int x, y, z;
cin>>x>>y>>z;
if(x == 1)Union(y, z);
else query(y, z);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CmNvbnN0IGludCBOID0gMWU1OwojZGVmaW5lIGxsIGxvbmcgbG9uZwp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG4sIG07CmludCBhW04rM107CnZlY3RvcjxtYXA8aW50LCBpbnQ+PiB2KE4rMyk7CmludCBwYXJlbnRbTiszXSwgc3pbTiszXTsKCnZvaWQgbWFrZSgpewogICAgZm9yKGludCBpPTE7aTw9bjtpKyspewogICAgICAgIHZbaV1bYVtpXV0gPSAxOwogICAgICAgIHBhcmVudFtpXSA9IGk7CiAgICAgICAgc3pbaV0gPSAxOwogICAgfQoKfQoKaW50IGZpbmQoaW50IHYpewogICAgaWYodiA9PSBwYXJlbnRbdl0pcmV0dXJuIHY7CiAgICBpbnQgcmVzID0gZmluZChwYXJlbnRbdl0pOwogICAgcGFyZW50W3ZdID0gcmVzOwogICAgcmV0dXJuIHJlczsKfQoKdm9pZCBVbmlvbihpbnQgYSwgaW50IGIpewogICAgYSA9IGZpbmQoYSk7CiAgICBiID0gZmluZChiKTsKICAgIGlmKGEgIT0gYil7CiAgICAgICAgaWYoc3pbYV0gPCBzeltiXSlzd2FwKGEsIGIpOwogICAgICAgIHBhcmVudFtiXSA9IGE7CiAgICAgICAgc3pbYV0gKz0gc3pbYl07CiAgICAgICAgZm9yKGF1dG8gcmVzIDogdltiXSl2W2FdW3Jlcy5maXJzdF0gKz0gcmVzLnNlY29uZDsKICAgICAgICB2W2JdLmNsZWFyKCk7CiAgICB9Cn0KCnZvaWQgcXVlcnkoaW50IGEsIGludCBiKXsKICAgIGEgPSBmaW5kKGEpOwogICAgaWYodlthXS5maW5kKGIpICE9IHZbYV0uZW5kKCkpY291dDw8dlthXVtiXTw8IlxuIjsKICAgIGVsc2UgY291dDw8MDw8IlxuIjsKfQoKaW50IG1haW4oKXsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwogICAgY2luPj5uPj5tOwogICAgZm9yKGludCBpPTE7aTw9bjtpKyspewogICAgICAgIGNpbj4+YVtpXTsKICAgIH0KCiAgICBtYWtlKCk7CiAgICB3aGlsZShtLS0pewogICAgICAgIGludCB4LCB5LCB6OwogICAgICAgIGNpbj4+eD4+eT4+ejsKICAgICAgICBpZih4ID09IDEpVW5pb24oeSwgeik7CiAgICAgICAgZWxzZSBxdWVyeSh5LCB6KTsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==