//I give up,I'm too dumb for this
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;


int main()
{
    cin.tie(0);
    std::ios_base::sync_with_stdio(false);

    long int n, input, u, v, q;
    vector<long int> Order;
    cin >> n;

    long int adjmatrix[n][n], helpermatrix[n][n];
    for(int i = 1; i <= n ; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            adjmatrix[i][j] = 0;
            helpermatrix[i][j] = 0;
        }
    }

    for(int i = 0; i < n; i++)
    {
       cin >> input;
       Order.push_back(input);
    }
    vector<long int> vertices;
    for(int i = 0; i < n - 1; i++)
    {
        cin >> u >> v;
        vertices.push_back(u);
        vertices.push_back(v);
        adjmatrix[u][v] = 1;
        adjmatrix[v][u] = 1;
    }

    for(int i = 1; i <= n ; i++)  //square the matrix
    {
        for(int j = 1; j <= n; j++)
        {
            helpermatrix[i][j] = 0;
            for(int k = 1; k <= n; k++)
            {
                helpermatrix[i][j] += adjmatrix[i][k]*adjmatrix[k][j];
            }
        }
    }

    cin >> q;  //second sequence of inputs
    long int pcase, a,b,l,r,x;
    vector<long int> finalres;
    for(int i = 0; i < q; i++)
    {
        cin >> pcase;
        if(pcase == 1)
        {
            cin >> a >> b;
            swap(Order[a-1], Order[b-1]);
           /* for(auto g : Order)
            {
                for(auto u : Order)
                {
                    adjmatrix[g][u] = 0;
                    helpermatrix[g][u] = 0;
                }
            }*/
            for(int o = 0; o < vertices.size() - 1; o+=2)
            {
                    adjmatrix[vertices[o]][vertices[o+1]]++;
                    adjmatrix[vertices[o+1]][vertices[o]]++;

            }
             for(int i1 = 1; i1 <= n ; i1++)  //square the matrix
            {
                for(int j = 1; j <= n; j++)
                {
                    helpermatrix[i][j] = 0;
                    for(int k = 1; k <= n; k++)
                    {
                        helpermatrix[i][j] += adjmatrix[i][k]*adjmatrix[k][j];
                    }
                }
            }


        }
        if(pcase == 2)
        {
            vector<long int> res;
            res.clear();
            cin >> l >> r >> x;
                long int m = l;
            for(int j = l; j <= (m + (r-m)); j++)
            {
                res.push_back(helpermatrix[l][l]);
            }

            sort(res.begin(), res.end());
            finalres.push_back(res[res.size()-1]);


        }
    }
    finalres[0] = finalres[0] + finalres[1];
    finalres[1] = 2 * finalres[1];
    finalres[2] = finalres[2] - 3 * finalres[1];
    for(auto w : finalres)
        cout << w << "\n";

    return 0;
}