#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 5;
int arr[MX], color[MX], p[MX], r[MX], par[MX];
void init(){
for(int i = 0; i < MX; i++){
color[i] = par[i] = -1;
p[i] = i;
r[i] = 0;
}
}
int find_par(int i){
return (p[i] == i) ? i :(p[i] = find_par(p[i]));
}
void union_set(int i, int j){
int x = find_par(i), y = find_par(j);
if(x != y){
if(r[x] > r[y]){
p[y] = x;
}else{
p[x] = y;
if(r[x] == r[y]) r[y]++;
}
}
}
int main() {
int t, n, q, id, u, v;
scanf("%d", &t);
for(int i = 1; i <= t; i++){
scanf("%d %d", &n, &q);
init();
for(int j = 1; j <= n; scanf("%d", &arr[j]), j++);
for(int j = 1; j <= n; j++){
if(color[arr[j]] == -1){
color[arr[j]] = j;
par[j] = arr[j];
}else{
int x = color[arr[j]];
union_set(x, j);
x = find_par(j);
color[arr[j]] = x;
par[x] = arr[j];
}
}
printf("Case %d:\n", i);
for(int j = 1; j <= q; j++){
scanf("%d %d", &id, &u);
if(id == 1){
scanf("%d", &v);
if(color[u] != -1){
if(color[v] != -1){
union_set(color[u], color[v]);
int x = find_par(color[u]);
color[v] = x;
par[x] = v;
}else{
color[v] = color[u];
par[color[u]] = v;
}
color[u] = -1;
}
}else{
int x = find_par(u);
printf("%d\n", par[x]);
}
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+IAp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1YID0gMWU1ICsgNTsgCmludCBhcnJbTVhdLCBjb2xvcltNWF0sIHBbTVhdLCByW01YXSwgcGFyW01YXTsKCnZvaWQgaW5pdCgpewoJZm9yKGludCBpID0gMDsgaSA8IE1YOyBpKyspewoJCWNvbG9yW2ldID0gcGFyW2ldID0gLTE7CgkJcFtpXSA9IGk7CgkJcltpXSA9IDA7Cgl9Cn0KCmludCBmaW5kX3BhcihpbnQgaSl7CglyZXR1cm4gKHBbaV0gPT0gaSkgPyBpIDoocFtpXSA9IGZ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