#include <iostream>
#include<vector>
#include<queue>
#define MAXN 80005

using namespace std;

struct change
{
	int type;
	int place_1_type_one;
	int place_2_type_one;
	int start_type_two;
	int end_type_two;
	int base_type_two;
};

int niz[MAXN];
int veze[MAXN][2];
change promene[MAXN];

bool visited[MAXN];
queue<int> q;

int max_distance[MAXN];

int main()
{
	int a;
	cin>>a;
	for(int i=0;i<a;i++) cin>>niz[i];
	for(int i=0;i<a-1;i++) cin>>veze[i][0]>>veze[i][1];
	int b;
	cin>>b;
	int max_distance_counter=0;
	int distance[a];
	for(int i=0;i<b;i++)
	{
		cin>>promene[i].type;
		if(promene[i].type==1) 
		{
			cin>>promene[i].place_1_type_one>>promene[i].place_2_type_one;
			int pom=niz[promene[i].place_1_type_one];
			niz[promene[i].place_1_type_one]=niz[promene[i].place_2_type_one];
			niz[promene[i].place_2_type_one]=pom;
		}
		else 
		{
			max_distance[max_distance_counter]=0;
			cin>>promene[i].start_type_two>>promene[i].end_type_two>>promene[i].base_type_two;
			q.push(promene[i].base_type_two);
			distance[promene[i].base_type_two]=0;
			visited[promene[i].base_type_two]=1;
			while(!q.empty())
			{
				int cvor=q.front();
				q.pop();
				for(int c: veze[cvor])
				{
					if(visited[c]!=1)
					{
						visited[c]=1;
						q.push(c);
						distance[c]=distance[cvor]+1;
					}
				}
			}
			for(int j=promene[i].start_type_two-1;j<=promene[i].end_type_two-1;j++) if(distance[niz[j]]>max_distance[max_distance_counter]) max_distance[max_distance_counter]=distance[niz[j]];
			max_distance_counter++;
		}
	}
	for(int i=0;i<max_distance_counter;i++)
	{
		cout<<max_distance[i]<<endl;
	}
	return 0;
}