#include <stdio.h>
#include <string.h>

#define N	200000
#define Q	50000
#define K	512
#define L	4096

int min(int a, int b) { return a < b ? a : b; }

int aa[N], bb[N], cc[N], ii[Q], xx[Q], n; char landmark[N], used[N];
int gg[N], ii_[K], aa_[K], bb_[K], cc_[K], k;
int col[N], l;
int kk[N + 1]; long long kk_[N];
int kka[K][L], kkb[K][L], kkc[K][L]; long long ans[N], kkba[K][L], kkac[K][L];

void setup(int hl, int hr) {
	int g, h, i, a, a_;
	long long x;

	for (h = hl; h < hr; h++) {
		i = ii[h];
		landmark[i] = 1;
		used[aa[i]] = used[bb[aa[i]]] = used[cc[aa[i]]] = 1;
		if (xx[h] != -1)
			used[xx[h]] = used[bb[xx[h]]] = used[cc[xx[h]]] = 1;
	}
	for (a = 0, l = 1; a < n; a++)
		col[a] = used[a] ? l++ : 0;
	k = 0;
	for (i = 0; i < n; i++)
		if (landmark[i])
			ii_[k] = i, aa_[k] = col[aa[i]], bb_[k] = col[bb[aa[i]]], cc_[k] = col[cc[aa[i]]], gg[i] = k++;

	memset(kk, 0, l * sizeof *kk);
	for (i = 0, g = 0; i < n; i++)
		if (!landmark[i]) {
			a = aa[i];
			kk[col[a]]++;
		} else
			memcpy(kka[g], kk, l * sizeof *kk), g++;

	memset(kk, 0, l * sizeof *kk), memset(kk_, 0, l * sizeof *kk_);
	for (i = 0, g = 0; i < n; i++)
		if (!landmark[i]) {
			a = aa[i];
			a_ = col[a], kk_[a_] += kk[a_];
			a_ = col[bb[a]], kk[a_]++;
		} else
			memcpy(kkba[g], kk_, l * sizeof *kk_), memcpy(kkb[g], kk, l * sizeof *kk), g++;

	memset(kk, 0, l * sizeof *kk), memset(kk_, 0, l * sizeof *kk_);
	for (i = n - 1, g = k - 1; i >= 0; i--)
		if (!landmark[i]) {
			a = aa[i];
			a_ = col[a], kk_[a_] += kk[a_];
			a_ = col[cc[a]], kk[a_]++;
		} else
			memcpy(kkac[g], kk_, l * sizeof *kk_), memcpy(kkc[g], kk, l * sizeof *kk), g--;

	memset(kk, 0, n * sizeof *kk), memset(kk_, 0, n * sizeof *kk_);
	x = 0;
	for (i = 0; i < n; i++)
		if (!landmark[i]) {
			a = aa[i];
			x += kk_[cc[a]], kk_[a] += kk[a], kk[bb[a]]++;
		} else
			ans[i] = x;
	for (h = hl; h < hr; h++) {
		i = ii[h];
		landmark[i] = 0;
		used[aa[i]] = used[bb[aa[i]]] = used[cc[aa[i]]] = 0;
		if (xx[h] != -1)
			used[xx[h]] = used[bb[xx[h]]] = used[cc[xx[h]]] = 0;
	}
}

int main() {
	static int ll[K];
	int q, h, hl, hr, i, a;

	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]), aa[i]--;
	for (i = 0; i < n; i++)
		scanf("%d", &bb[i]), bb[i]--;
	for (i = 0; i < n; i++)
		scanf("%d", &cc[i]), cc[i]--;
	for (h = 0; h < q; h++) {
		int t;

		scanf("%d%d", &t, &ii[h]), ii[h]--;
		if (t == 1)
			scanf("%d", &xx[h]), xx[h]--;
		else
			xx[h] = -1;
	}
	for (hl = 0; hl < q; hl += K) {
		hr = min(hl + K, q);
		setup(hl, hr);
		for (h = hl; h < hr; h++)
			if (xx[h] != -1) {
				i = ii[h], a = xx[h];
				aa[i] = a, aa_[gg[i]] = col[a], bb_[gg[i]] = col[bb[a]], cc_[gg[i]] = col[cc[a]];
			} else {
				int r, k_, g, a, b, c;
				long long x;

				r = ii[h], k_ = gg[r] + 1;
				x = ans[r];	/* no landmarks */
				memset(kk_, 0, l * sizeof *kk_), memset(kk, 0, l * sizeof *kk);
				for (g = 0; g < k_; g++) {
					a = aa_[g], b = bb_[g], c = cc_[g];
					x += (kkba[g][c]) + (kkac[g][b] - kkac[k_ - 1][b] - (long long) (kka[k_ - 1][b] - kka[g][b]) * kkc[k_ - 1][b]) + ((long long) kk[c] * kka[g][c] - kk_[c]);	/* c landmark, b landmark, b and c landmark */
					ll[g] = kkb[g][a] + kk[a], kk[b]++, kk_[b] += kka[g][b];
				}
				memset(kk, 0, l * sizeof *kk);
				for (g = k_ - 1; g >= 0; g--) {
					a = aa_[g], c = cc_[g];
					x += (long long) ll[g] * (kkc[g][a] - kkc[k_ - 1][a] + kk[a]);	/* [b], a, and [c] landmark */
					kk[c]++;
				}
				printf("%lld\n", x);
			}
	}
	return 0;
}
