#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <list>
#include <algorithm>
#include <iostream>
#include <climits>
#include <string.h>

struct dogadjaj
{
	int tip;
	int pocetak;
	int kraj;
	int mesto = -1;
};

int main()
{
	int n;
	std::string input;
	scanf("%d ", &n);
	std::vector<int> redosled;
	std::vector<int> naselja[n];
	int* p = (int*)malloc(n*sizeof(int));
	int* d = (int*)malloc(n*sizeof(int));
	std::vector<dogadjaj> dogadjaji;

	std::getline(std::cin, input);
	char* c = (char*)input.c_str();
	char* tok;
	tok = strtok(c, " ");
    for(int j = 0; j < n; j++)
    {
		int id = atoi(tok);
		redosled.push_back(id);
        tok = strtok(NULL, " ");
    }

	for(int i = 0; i < n-1; i++)
	{
		int x, y;
		if(i == n-2)
		{
			scanf("%d %d", &x, &y);
		}
		else
		{
			scanf("%d %d ", &x, &y);
		}
		naselja[x-1].push_back(y-1);
		naselja[y-1].push_back(x-1);
	}

	int q;
	scanf("%d ", &q);

	for(int i = 0; i < q; i++)
	{
		int x, y, z, w;

		std::getline(std::cin, input);
		c = (char*)input.c_str();

		tok = strtok(c, " ");
		x = atoi(tok);
		tok = strtok(NULL, " ");
		y = atoi(tok);
		tok = strtok(NULL, " ");
		z = atoi(tok);
		if(x == 2)
		{
			tok = strtok(NULL, " ");
			w = atoi(tok);
		}

		dogadjaj d;
		d.tip = x;
		d.pocetak = y;
		d.kraj = z;
		if(x == 2) d.mesto = w;

		dogadjaji.push_back(d);
	}
	for(int i = 0; i < q; i++)
	{
		if(dogadjaji[i].tip == 1)
		{
			std::swap(redosled[dogadjaji[i].pocetak-1], redosled[dogadjaji[i].kraj-1]);
		}
		else if(dogadjaji[i].tip == 2)
		{
			int max_dist = 0;
			for(int k = dogadjaji[i].pocetak-1; k <= dogadjaji[i].kraj-1; k++)
			{
				int node = dogadjaji[i].mesto-1;
				std::list<int> q;
				bool* visited_nodes = (bool*)malloc(n*sizeof(bool));
				for(int j = 0; j < n; j++)
				{
					p[j] = -1;
					d[j] = INT_MAX;
					visited_nodes[j] = false;
				}
				visited_nodes[node] = true;
				d[node] = 0;
				q.push_back(node);
				
				while(!q.empty())
				{
					int x = q.front();
					q.pop_front();
					for (int j = 0; j < naselja[x].size(); j++)
					{
						if (visited_nodes[naselja[x][j]] == false) 
						{
							visited_nodes[naselja[x][j]] = true;
							d[naselja[x][j]] = d[x] + 1;
							p[naselja[x][j]] = x;
							q.push_back(naselja[x][j]);
							
							if (naselja[x][j] == redosled[k]-1)
							{
								if(max_dist < d[redosled[k]-1])
									max_dist = d[redosled[k]-1];
								q.clear();
								break;
							}
						}
					}
				}
			}
			printf("%d\n", max_dist);
		}
	}
	return 0;
}