#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")

#define f(i,a,b) for(ll  i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for(ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll  i = a; i < (ll) b ; i+= k )
#define arep(i,a,b,k) for(ll i = a; i >= (ll) b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define sz(a) (ll) a.size()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter   ios::sync_with_stdio(false);cin.tie(0)

// policy-based



using namespace std;

typedef int ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

const ll MAX = 3e5 + 10;
const ll mod = 998244353;
const ll inf = 1e9;

ll n,q,p[MAX],sz[MAX];

map< ll ,ll > m[MAX];
void ini(){
	f(i,1,n+1) p[i] = i, sz[i] = 1;
}

ll find(ll u){
	return (p[u] == u? u : p[u] = find(p[u]));
}

void uni(ll u,ll v){
	ll x = find(u), y = find(v);
	if(x == y) return;
	if( sz[x] > sz[y]) swap(x,y);
	for(ii it:m[x]) m[y][it.ff] += it.ss; 
	m[x].swap(m[y]);
	p[y] = x;
	sz[x] += sz[y];

}

int main(){
	fastio;
	ll t,u,v;
	cin >> n >> q;
	ini();
	f(i,1,n+1) cin >> u, m[i][u]++;
	while(q--){
		cin >> t >> u >> v;
		if(t == 1) uni(u,v);
		else cout << m[find(u)][v] << endl;
	}	
    return 0;
}
//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//mapとか考えもしなかったしさっさと引退しろって感じですね

const int SZ = 200000;
int P[SZ + 1];
int find(int A) {
	if (P[A] < 0) return A;
	return P[A] = find(P[A]);
}
int N, Q;
int C[200001];
int ne[200001], he[200001];
ll to[200001];
int A[200001];
int c[200001], kotae[200001];

const int CM = 1 << 17, CL = 16;
char cn[CM + CL], * ci = cn + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int MAX = 1000;
class shuturyoku_unko {
public:
	char C[MAX * 4];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 3) {
				C[i * 4 + 2 - j] = '0' + X % 10;
				X /= 10;
			}
			C[i * 4 + 3] = '\n';
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char* dn = cn, * di = dn, * owad = dn + dm - 20;
void putint(int A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	if (A >= 1000) {
		int dig = 1;
		if (A >= 100000) dig = 3;
		else if (A >= 10000) dig = 2;
		memcpy(di, f.C + A / 1000 * 4 + 3 - dig, dig);
		memcpy(di + dig, f.C + A % 1000 * 4, 4);
		di += dig + 4;
	}
	else {
		int dig = 1;
		if (A >= 100) dig = 3;
		else if (A >= 10) dig = 2;
		memcpy(di, f.C + A * 4 + 3 - dig, dig + 1);
		di += dig + 1;
	}
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	fread(cn + CL, 1, CM, stdin);

	N = getint();
	Q = getint();
	rep1(i, N) {
		if (ci - owa > 0) {
			memcpy(cn, owa, CL);
			ci -= CM;
			fread(cn + CL, 1, CM, stdin);
		}
		C[i] = getint();
	}

	rep1(i, SZ) P[i] = -1;

	int k = 1;
	rep1(i, Q) {
		if (ci - owa > 0) {
			memcpy(cn, owa, CL);
			ci -= CM;
			fread(cn + CL, 1, CM, stdin);
		}
		char c = *ci;
		ci += 2;
		if (c == '1') {
			int a = getint(), b = getint();
			a = find(a);
			b = find(b);
			if (a != b) {
				if (P[a] > P[b]) swap(a, b);
				P[a] += P[b];
				P[b] = a;
				to[k] = b;
				ne[k] = he[a];
				he[a] = k++;
			}
		}
		else {
			int a = getint(), b = getint();
			a = find(a);
			to[k] = (ll)i << 30 | b;
			ne[k] = he[a];
			he[a] = k++;
		}
	}

	int k2 = 0;
	rep1(i, N) {
		if (P[i] < 0) {
			A[k2++] = i;
			while (k2) {
				int a = A[--k2];
				if (a > 0) {
					for (int j = he[a]; j; j = ne[j]) {
						ll t = to[j];
						if (t >> 30) {
							kotae[t >> 30] = 1000000 - c[t & ((1 << 20) - 1)];
							A[k2++] = -j;
						}
						else {
							A[k2++] = t;
						}
					}
					c[C[a]]++;
				}
				else {
					ll t = to[-a];
					kotae[t >> 30] += c[t & ((1 << 20) - 1)];
				}
			}
		}
	}

	rep1(i, Q) {
		if (kotae[i] >= 1000000) putint(kotae[i] - 1000000);
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}