#include<bits/stdc++.h>
using namespace std;
const int maxn=80010;
vector<int>graf[maxn];
int c[maxn];
int distance1[3][maxn];
queue<int>q;
int n;
void bfs(int node)
{
    distance1[node][node]=0;
    q.push(node);
    while (!q.empty())
    {
        int s=q.front();
        q.pop();
        for (auto x: graf[s])
        {
            if (distance1[node][x]) continue;
            distance1[node][x]=distance1[node][s]+1;
            q.push(x);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for (int i=1; i<=n; i++)
        cin >> c[i];
    for (int i=0; i<n-1; i++)
    {
        int a,b;
        cin >> a >> b;
        graf[a].push_back(b);
        graf[b].push_back(a);
    }
    bfs(1);
    int k;
    cin >> k;
    while (k--)
    {
        int t;
        cin >> t;
        if (t==1)
        {
            int a,b;
            cin >> a >> b;
            swap(c[a],c[b]);
            continue;
        }
        int l,r;
        cin >> l >> r;
        int x;
        cin >> x;
        int m=distance1[x][c[l]];
        for (int i=l+1; i<=r; i++)
            m=max(m,distance1[x][c[i]]);
        cout << m << "\n";
    }
    return 0;
}