using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {

        static int najdalje(bool [,] m, int n, int x, int y)
        {
            bool[] poseceni = new bool[n];
            int[] prethodnici = new int[n];
            poseceni[x] = true;
            prethodnici[x] = -1;
            int[] red = new int[n];
            int i = 0;
            int l = 1;
            red[0] = x;
            while (i < l) 
            {
                for (int j = 0; j < n; j++)
                {
                    if (m[red[i], j] && !poseceni[j])
                    {
                        poseceni[j] = true;
                        red[l] = j;
                        l++;
                        prethodnici[j] = red[i];
                    }
                }
                i++;
            }
            int k = y;
            int br = 0;
            while (k != x)
            {
                k = prethodnici[k];
                br++;
            }
            return br;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            String[] s = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(s[i]);
            bool[,] m = new bool[n, n];
            for (int i = 0; i < n - 1; i++)
            {
                String[] l = Console.ReadLine().Split();
                int u = int.Parse(l[0]);
                int v = int.Parse(l[1]);
                m[u - 1, v - 1] = true;
                m[v - 1, u - 1] = true;
            }
            int n1 = int.Parse(Console.ReadLine());
            List<int> li = new List<int>();
            for (int i = 0; i < n1; i++)
            {
                String[] l1 = Console.ReadLine().Split();
                if (int.Parse(l1[0]) == 1)
                {
                    int p = int.Parse(l1[1]);
                    int q = int.Parse(l1[2]);
                    int p1 = a[q - 1];
                    a[q - 1] = a[p - 1];
                    a[p - 1] = p1;
                }
                int max = int.MinValue;
                if (int.Parse(l1[0]) == 2)
                {
                    int p = int.Parse(l1[1]);
                    int q = int.Parse(l1[2]);
                    int r = int.Parse(l1[3]);
                    for (int j = p - 1; j <= q - 1; j++) 
                    {
                        int nn = najdalje(m, n, a[j] - 1, r - 1);
                        if (nn > max)
                            max = nn;
                    }
                    li.Add(max);
                }
            }
            foreach (int br in li)
                Console.WriteLine(br);
        }
    }
}