import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class Main1
{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] cities = br.readLine().split(" ");
        int[] cityOrder = new int[cities.length];
        HashMap<Integer,int[]> roads = new HashMap<>();
        ArrayList<String> roadsArray = new ArrayList<>();
        for(int i = 0; i < cities.length;i++)
        {
            cityOrder[i] = Integer.parseInt(cities[i]);
        }
        for(int i = 0; i < n-1;i++)
        {
            String tempRoad = br.readLine();
            roadsArray.add(tempRoad);
        }
        int q = Integer.parseInt(br.readLine());
        String[] komande = new String[q];
        for(int i = 0; i < q;i++)
        {
            komande[i] = br.readLine();
        }
            for(int i = 0; i < cityOrder.length;i++)
            {
                int currentCity = cityOrder[i];
                int[] currentCityRoads = new int[n-1];
                int counter = 0;
                for(int j = 0; j < roadsArray.size();j++)
                {
                    String[] currentRoad = roadsArray.get(j).split(" ");
                        if (Integer.parseInt(currentRoad[0]) == currentCity) {
                            currentCityRoads[counter] = Integer.parseInt(currentRoad[1]);
                            counter++;
                        } else if (Integer.parseInt(currentRoad[1]) == currentCity) {
                            currentCityRoads[counter] = Integer.parseInt(currentRoad[0]);
                            counter++;
                        }
                roads.put(currentCity,currentCityRoads);
            }
        }
            for(int i = 0; i < q; i++)
            {
                String currentCommand = komande[i];
                if(currentCommand.charAt(0) == '1')
                {
                    try {
                        cityOrder = swapCities(Integer.parseInt(currentCommand.substring(2, 4)), Integer.parseInt(currentCommand.substring(4, 6)), cityOrder);
                    }
                    catch (NumberFormatException e)
                    {
                        cityOrder = swapCities(Integer.parseInt(currentCommand.substring(2, 3)), Integer.parseInt(currentCommand.substring(4, 5)), cityOrder);
                    }
                    //roads = swapKeys(Integer.parseInt(currentCommand.substring(2,3)),Integer.parseInt(currentCommand.substring(4,5)),roads);
                }
                String[] splitCommands = currentCommand.split(" ");
                if(splitCommands[0].equals("2"))
                {
                    System.out.println(findRange(Integer.parseInt(splitCommands[1]),Integer.parseInt(splitCommands[2]),Integer.parseInt(splitCommands[3]),roads,cityOrder));
                }
            }
    }

    public static int findRange(int l, int r, int x, HashMap<Integer,int[]> map,int[] order)
    {
        int length = 0;
        for(int i2 = l-1 ; i2 <= r-1;i2++)
        {
            int i = order[i2];
            int[] jumps = map.get(x);
            ArrayList<Integer> wrongturns  = new ArrayList<>();
            ArrayList<Integer> path = new ArrayList<>();
            int currentTile = x;
            while (currentTile != i) {
                if (contains(jumps, i)) {
                    path.add(i);
                    currentTile = i;
                } else {
                    if (getCount(jumps) == 1 && path.contains(jumps[0])) {
                        if (jumps[0] == path.get(path.size() - 1)) {
                            int[] tempJump = jumps;
                            int badTile = 0;
                            while (getCount(tempJump) == 0 && tempJump[0] == path.get(path.size() - 1)) {
                                badTile = tempJump[0];
                                tempJump = map.get(tempJump[0]);
                                path.remove(path.size() - 1);
                            }
                            wrongturns.add(badTile);
                        }
                    }
                    int c = 0;
                    while (wrongturns.contains(jumps[c])) {
                        c++;
                    }
                    if (c == 0) {
                        while (path.contains(jumps[c])) {
                            c++;
                        }
                    }
                    if (path.size() == 0) {
                        path.add(currentTile);
                    }
                    currentTile = jumps[c];
                    jumps = map.get(jumps[c]);
                    path.add(currentTile);
                }
            }
            path.remove(0);
            if(length < path.size())
            {
                length = path.size();
            }
        }
        return length;
    }

    public static boolean contains(final int[] arr, final int key) {
        return Arrays.stream(arr).anyMatch(i -> i == key);
    }

    public static int getCount(int[] arr)
    {
        int count = 0;
        for(int i = 0; i < arr.length;i++)
        {
            if (arr[i] != 0) {
                count++;
            }
        }
        return count;
    }

    public static int[] swapCities(int key1,int key2,int[] cityOrder)
    {
        int[] newOrder = new int[cityOrder.length];
        for(int i = 0; i < newOrder.length;i++)
        {
            if(i == key1-1)
            {
                newOrder[i] = cityOrder[key2-1];
            }
            else if(i == key2-1)
            {
                newOrder[i] = cityOrder[key1-1];
            }
            else
            {
                newOrder[i] = cityOrder[i];
            }
        }
        return newOrder;
    }

  /*  public static HashMap<Integer,int[]> swapKeys(int key1,int key2,HashMap<Integer,int[]> h)
    {
        HashMap<Integer,int[]> newH = new HashMap<>();
        for(int i =1 ; i < h.size()+1;i++)
        {
            if(i == key1)
            {
                newH.put(key2,h.get(key1));
            }
            else if(i == key2)
            {
                newH.put(key1,h.get(key2));
            }
            else
            {
                newH.put(i,h.get(i));
            }
        }
        return newH;
    }*/
}