#include <iostream>
#include <stdio.h>
#include <list>
#include <queue>
#include <cmath>
#include <stdlib.h>
using namespace std;

int main()
{
    long long n;
    cin >> n;
    long long niz[n];

    for(int i=0;i<n;i++)
    {
        cin>>niz[i];
    }

    list<pair<long long ,long long>> grafik[n];
    for (long long i = 0; i < n-1; i++)
    {
        long long u,v;
        scanf("%d%d", &u, &v);
        grafik[u-1].push_back({v-1,1});
        grafik[v-1].push_back({u-1,1});
    }

    long long q;
    cin>>q;

    queue<long long> resenja;
    for(int ii=0; ii<q;ii++)
    {
        int broj;
        cin>>broj;
        if(broj==1)
            {
                long long a,b;
                cin>>a>>b;
                long long k;
                k=niz[a-1];
                niz[a-1]=niz[b-1];
                niz[b-1]=k;

            }
        if(broj==2)
            {
                long long l,r,x;
                cin>>l>>r>>x;
                x=x-1;
                long long maksimum=0;
                for(int i =l-1; i<r;i++)
                    {
                        long long y=niz[i]-1;
                        long long d[n];
                        queue<long long> red;
                        bool posecen[n];
                        for(long long i=0;i<n;i++){
                            posecen[i]=false;
                        }

                            for (long long i = 0; i < n; i++) d[i] = 999999;
                            d[x] = 0;
                            red.push(x);
                            while (!red.empty()) {
                                long long h = red.front();
                                red.pop();

                                if (posecen[h])
                                {
                                        continue;
                                }
                                posecen[h] = true;

                                for (auto o : grafik[h]) {
                                    long long s2 = o.first;
                                    long long s1 = o.second;
                                    if (d[h] + s1 < d[s2]) {
                                        d[s2] = d[h] + s1;
                                        red.push(s2);
                                    }
                                }
                            }

                            long long razdaljina=d[y];
                            if(razdaljina>maksimum){ maksimum=razdaljina;}
                    }
            resenja.push(maksimum);
            }

    }

    while(!resenja.empty()){
		cout<<resenja.front()<<endl;
		resenja.pop();
	}



return 0;
}