using System;
using System.Collections.Generic;
//using System.Console;

namespace PrettyIntegers
{
    class Program
    {
        public static void Main(string[] args)
        {
            int n,m;
            n = Console.Read();
            m = Console.Read();
            List<int> N = new List<int>();
            List<int> M = new List<int>();

            for(int i = 0; i<n; i++)
            {
                N.Insert(Console.Read());
            }
            N.Sort();

            for(int i = 0; i<m; i++)
            {
                M.Insert(Console.Read());
            }

            //First check for the common Elements
            foreach (int i in N)
            {
                if(M.Contains(i))
                {
                    Console.WriteLine(i);
                    return;
                }
            }

            //Now do the other thing
            int OneTwo = N.Min()*10 + M.Min(), TwoOne = M.Min()*10 + N.Min();
            Console.WriteLine(Math.Min(OneTwo, TwoOne));
            Console.Read();
        }
    }
}using System;
using System.Collections.Generic;
//using System.Console;

namespace PrettyIntegers
{
    class Program
    {
        public static void Main(string[] args)
        {
            int n,m;
            string[] parts = Console.ReadLine().Split(' ');
            n = int.Parse(parts[0]);
            m = int.Parse(parts[1]);
            List<int> N = new List<int>();
            List<int> M = new List<int>();

            parts = Console.ReadLine().Split(' ');
            for(int i = 0; i<n; i++)
            {
                N.Add(int.Parse(parts[i]));
            }
            N.Sort();

            parts = Console.ReadLine().Split(' ');
            for(int i = 0; i<m; i++)
            {
                M.Add(int.Parse(parts[i]));
            }
            M.Sort();

            //First check for the common Elements

            foreach (int i in N)
            {
                if(M.Contains(i))
                {
                    Console.WriteLine(i);
                    return;
                }
            }

            //Now do the other thing
            int min1 = N[0];
            int min2 = M[0];
            int OneTwo = min1*10 + min2, TwoOne = min2*10 + min1;
            Console.WriteLine(Math.Min(OneTwo, TwoOne));
            //Console.Read();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] toks = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = toks[0];
            int m = toks[1];
            int[] s1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Array.Sort(s1);
            int[] s2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Array.Sort(s2);
            for(int i = 0; i < s1.Length; i++)
            {
                if (s2.Contains(s1[i]))
                {
                    Console.WriteLine(s1[i]);
                    return;
                }
            }
            List<int> res = new List<int>();
            for(int i = 0; i < s1.Length; i++)
            {
                StringBuilder tempo = new StringBuilder();
                tempo.Append(s1[i]);
                for (int j = 0;  j < s2.Length; j++)
                {
                    tempo.Append(s2[j]);
                    res.Add(int.Parse(tempo.ToString()));
                    tempo.Remove(1, 1);
                }
            }
            Console.WriteLine(res.Min());
            Console.ReadLine();
        }
    }
}


using System;

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            var nbr = int.Parse(Console.ReadLine());

            Console.WriteLine((nbr % 2 == 0 && ((nbr /2) % 2 == 0)  ? "YES" : "NO");
        }
    }
}


using System;
public class Program
{
    public static void Main()
    {
        byte W;

        if (byte.Parse(Console.ReadLine()) == 2)
        {
            Console.WriteLine("NO");
        }
        else
        {
            if (byte.Parse(Console.ReadLine()) % 2 == 0)
                {
                    Console.WriteLine("YES");
                }
            else
                {
                    Console.WriteLine("NO");
                }
        }

    }
}


        private static string CheckEven(int x)
        {
            if (x%2==0)
            {
                return "YES";
            }
            else
            return "NO";
        }


using System;

namespace Watermelon
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Console.WriteLine(args[0]);
        }
    }
}


private static void Main(string[] args)
{
    Console.WriteLine(args[0]);
}


using System;

namespace Watermelon
{
    internal class Program
    {
        private static void Main()
        {
            string line;
            while ((line = Console.ReadLine()) != string.Empty)
            {
                Console.WriteLine(line);
            }
        }
    }
}


namespace Watermelon {
    class Program {
        static void Main(string[] args) {
            string w = Console.ReadLine();
            int weight = Convert.ToInt32(w);
            if (weight % 2 == 0) {
                Console.WriteLine("YES");
            } else {
                Console.WriteLine("NO");
            }
        }
    }
}


int w = Convert.ToInt32(Console.ReadLine());

            if (w/2 % 2 == 0)
            {
                Console.WriteLine("YES");
            }


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30611.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp5", "ConsoleApp5\ConsoleApp5.csproj", "{621884C1-8947-4892-8ADD-3D869542F695}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{621884C1-8947-4892-8ADD-3D869542F695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{621884C1-8947-4892-8ADD-3D869542F695}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{621884C1-8947-4892-8ADD-3D869542F695}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{621884C1-8947-4892-8ADD-3D869542F695}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {E3D8F1A6-2043-401B-A41C-BD2B4213C5AA}
	EndGlobalSection
EndGlobal


using System;

namespace WaterMillon
{
    class Program
    {
        static void Main(string[] args)
        {
            Int16 kilos = 0;

            kilos = Convert.ToInt16(args[0]);
            if (kilos > 2 && kilos % 2 == 0)
                Console.Out.WriteLine("YES");
            else
                Console.Out.WriteLine("NO");

        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace CF
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
			{
				//using (var sw = new StreamWriter("output.txt")) {
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArrayOfInt32();
			var x1 = input[0];
			var y1 = input[1];
			var x2 = input[2];
			var y2 = input[3];
			input = sr.ReadArrayOfInt32();
			var x = input[0];
			var y = input[1];
			var dx = Math.Abs(x2 - x1);
			var dy = Math.Abs(y2 - y1);
			var rx = dx / x;
			if (dx % x != 0)
			{
				sw.WriteLine("NO");
				return;
			}
			var ry = dy / y;
			if (dy % y != 0)
			{
				sw.WriteLine("NO");
				return;
			}
			if (rx == 0 || ry == 0)
			{
				sw.WriteLine("YES");
				return;
			}
			if (Math.Abs(rx - ry) % 2 == 0) {
				sw.WriteLine("YES");
				return;
			}

			sw.WriteLine("NO");
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
										.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
										.Select(s => func(s, CultureInfo.InvariantCulture))
										.ToArray();
	}

	public int[] ReadArrayOfInt32()
	{
		return ReadArray(Int32.Parse);
	}

	public long[] ReadArrayOfInt64()
	{
		return ReadArray(Int64.Parse);
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
										str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
																		.Select(s => func(s, CultureInfo.InvariantCulture))
																		.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose)
		{
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}


using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ConsoleApplication1.CodeForces
{
    class _4032
    {
        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

        class Node : IComparable
        {
            public long X { get; set; }
            public long Y { get; set; }
            public int CompareTo(object obj)
            {
                if (this.Y > ((Node)obj).Y)
                {
                    return 1;
                }
                if (this.Y == ((Node)obj).Y)
                {
                    return 0;
                }
                return -1;
            }
        }

        static void Main(String[] args)
        {
            var data = Console.ReadLine().TrimEnd().Split(' ').Select(double.Parse).ToList();
            var x1 = data[0];
            var y1 = data[1];
            var x2 = data[2];
            var y2 = data[3];
            data = Console.ReadLine().TrimEnd().Split(' ').Select(double.Parse).ToList();
            var x = data[0];
            var y = data[1];

            double k1 = (x2 - x1) / x;
            double k2 = (y2 - y1) / y;

            if(k1 % 1 ==0 && k2 % 1== 0 && k1%2==k2%2)
            {
                Console.WriteLine("YES");
            } else
            {
                Console.WriteLine("NO");

            }
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HayCragrer
{
    class Problem4
    {
        static void Main(string[] args)
        {
            int[] coords = new int[4];
            string[] text = Console.ReadLine().Split();
            string[] text1 = Console.ReadLine().Split();
            int[] steps = new int[2];
            for (int i = 0; i < 4; i++)
            {
                coords[i] = int.Parse(text[i]);
            }
            for (int i = 0; i < 2; i++)
            {
                steps[i] = int.Parse(text1[i]);
            }
            int x = coords[2] - coords[0];
            int y = coords[3] - coords[1];
            if ((x % steps[0] == 0) && (y % steps[1] == 0))
            {
                if ((x / steps[0] -y / steps[1]) % 2==0)
                {
                    Console.WriteLine("YES");
                }

            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


using System;
class Program
    {
        static void Main(string[] args)
        {
            int[] frts, sec;
            {
                string[] input = Console.In.ReadToEnd().Split(new char[] { ' ', '\n', '\r', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                int n = int.Parse(input[0]);
                frts = new int[n++];
                for (int i = 2, j = 0; i <= n; ++i, j++)
                 frts[j] = int.Parse(input[i]);
                sec = new int[input.Length - n++];
                for (int j = 0; n < input.Length; ++n, ++j)
                  sec[j] = int.Parse(input[n]);
            }
            Array.Sort(frts);
            int nm = int.MinValue;
            for(int i = 0; i<frts.Length; ++i)
             if(sec.Contains(frts[i]))
                { nm = i; break; }
            if (nm >= 0) Console.WriteLine(frts[nm]);
            else
            {
                nm = sec.Min();
                if (nm > frts[0]) Console.WriteLine("{0}{1}", frts[0], nm);
                else Console.WriteLine("{0}{1}", nm, frts[0]);
            }
        }
    }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main()
        {
            string[] a1 = Console.ReadLine().Split(' ');
            int c1 = Convert.ToInt32(a1[0]);
            int c2 = Convert.ToInt32(a1[1]);

            a1 = Console.ReadLine().Split(' ');
            string[] a2 = Console.ReadLine().Split(' ');

            int minn = 10;
            int min1 = 10;
            int min2 = 10;

            for (int i = 0; i < c1; i++)
            {
                if (Convert.ToInt32(a1[i]) < min1)
                {
                    min1 = Convert.ToInt32(a1[i]);
                }
                for (int j = 0; j < c2; j++)
                {
                    if (Convert.ToInt32(a2[i]) < min2)
                    {
                        min2 = Convert.ToInt32(a2[i]);
                    }
                    if (a1[i] == a2[j])
                    {
                        if (Convert.ToInt32(a1[i]) < minn)
                        {
                            minn = Convert.ToInt32(a1[i]);
                        }
                    }
                }
            }

            if (minn != 10)
            {
                Console.WriteLine("{0}",minn);
            }
            else
            {
                if (min1 < min2)
                {
                    Console.WriteLine("{0}{1}", min1, min2);
                }
                else
                {
                    Console.WriteLine("{0}{1}", min2, min1);
                }
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Flipping_Game
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int maxCount = 0;
            for (int i = 0; i < numbers.Length; i--)
            {
                for (int j = 0; j < numbers.Length; j++)
                {
                    int count = 0;
                    for (int k = 0; k < numbers.Length; k++)
                    {
                        if (k <= j && k >= i)
                        {
                            count += 1 - numbers[k];
                        }
                        else
                        {
                            count += numbers[k];
                        }
                    }
                    maxCount = Math.Max(count, maxCount);
                }
            }
            Console.WriteLine(maxCount);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Flipping_Game
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int maxCount = 0;
            for(int i = 0; i < numbers.Length;i++)
            {
                for (int j = 0; j < numbers.Length; j++)
                {
                    int count = 0;
                    for (int k = 0; k < numbers.Length; k++)
                    {
                        if (k >= i && k <= j)
                        {
                            if (numbers[k] == 0)
                                count++;
                        }
                        else
                        {
                            if (numbers[k] == 1)
                                count++;
                        }
                    }
                    maxCount = Math.Max(count, maxCount);
            }
            Console.WriteLine(maxCount);
        }
    }
}


using System;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            int s;
            int t = 0;
            int jami = 0;
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
                jami += a[i];

            }
            s = jami;
            for (int i = 0; i < n; i++)
            {
                jami = s;
                if (a[i] == 0)
                {
                    jami += 1;
                }
                if (a[i] == 1)
                {
                    jami -= 1;
                }
                for (int j = i + 1; j < n; j++)
                {
                    if (a[j] == 0)
                    {
                        jami += 1;
                    }
                    if (a[j] == 1)
                    {
                        jami -= 1;
                    }
                    if (jami > t)
                    {
                        t = jami;
                    }

                }
            }

            Console.WriteLine(t);

        }
    }
}


using System;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(n);
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int s;
            int t = 0;

            int jami = 0;
            for (int i = 0; i < n; i++)
            {

                jami += a[i];

            }
            s = jami;
            for (int i = 0; i < n; i++)
            {
                jami = s;
                if (a[i] == 0)
                {
                    jami += 1;
                }
                if (a[i] == 1)
                {
                    jami -= 1;
                }
                for (int j = i + 1; j < n; j++)
                {
                    if (a[j] == 0)
                    {
                        jami += 1;
                    }
                    if (a[j] == 1)
                    {
                        jami -= 1;
                    }
                    if (jami > t)
                    {
                        t = jami;
                    }

                }
            }

            Console.WriteLine(t);

        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ProblemD
    {
        static bool SAIKI = false;
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = NN;
            var m = NN;
            var q = NN;
            var pList = NNList(n);
            var ab = Repeat(0, m).Select(_ => new { a = NN - 1, b = NN - 1 }).ToArray();
            var query = Repeat(0, q).Select(_ => new { t = NN, param = NN }).ToArray();
            var deleteTgt = new bool[m];
            var uf = new LIB_UnionFind<LIB_PriorityQueue>(pList.Select((e, idx) =>
            {
                var ret = new LIB_PriorityQueue();
                ret.Push(e, idx);
                return ret;
            }), (x, y) =>
            {
                if (x.Count > y.Count)
                {
                    for (var i = 0; i < y.Count; i++)
                    {
                        x.Push(y.heap[i], y.dat[i]);
                    }
                    return x;
                }
                else
                {
                    for (var i = 0; i < x.Count; i++)
                    {
                        y.Push(x.heap[i], x.dat[i]);
                    }
                    return y;
                }
            });
            foreach (var item in query)
            {
                if (item.t == 2) deleteTgt[item.param - 1] = true;
            }
            for (var i = 0; i < m; i++)
            {
                if (!deleteTgt[i])
                {
                    uf.Unite(ab[i].a, ab[i].b);
                }
            }
            var ans = new List<LIB_PriorityQueue>();
            for (var qqq = q - 1; qqq >= 0; qqq--)
            {
                if (query[qqq].t == 1)
                {
                    var v = query[qqq].param - 1;
                    ans.Add(uf.Calc(v));
                }
                else
                {
                    var i = query[qqq].param - 1;
                    uf.Unite(ab[i].a, ab[i].b);
                }
            }
            ans.Reverse();
            var deleted = new bool[n];
            foreach (var item in ans)
            {
                var ok = false;
                while (item.Count > 0)
                {
                    var value = item.Pop();
                    if (!deleted[value.Value])
                    {
                        deleted[value.Value] = true;
                        Console.WriteLine(value.Key);
                        ok = true;
                        break;
                    }
                }
                if (!ok) Console.WriteLine(0);
            }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector);
        static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
        static bool Chmax<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) < 0) { lhs = rhs; return true; } return false; }
        static bool Chmin<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) > 0) { lhs = rhs; return true; } return false; }
    }
}
namespace Library {
    class LIB_FastIO
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[2048];
        int len, ptr;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        byte read()
        {
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 2048)) <= 0)
                {
                    return 0;
                }
            }
            return buf[ptr++];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = (ret << 3) + (ret << 1) + b - '0';
            }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIODebug() { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string Scan() => NextString();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override long Long() => long.Parse(NextString());
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override double Double() => double.Parse(NextString());
    }
    class LIB_UnionFind<T>
    {
        int[] d;
        T[] v;
        Func<T, T, T> f;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_UnionFind(IEnumerable<T> s, Func<T, T, T> func)
        {
            v = s.ToArray();
            d = Enumerable.Repeat(-1, v.Length).ToArray();
            f = func;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Unite(long x, long y)
        {
            x = Root(x);
            y = Root(y);
            if (x != y)
            {
                d[x] = d[x] + d[y];
                v[x] = f(v[x], v[y]);
                d[y] = (int)x;
            }
            return x != y;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool IsSame(long x, long y) => Root(x) == Root(y);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public long Root(long x) => d[x] < 0 ? x : d[x] = (int)Root(d[x]);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public long Count(long x) => -d[Root(x)];
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public T Calc(long x) => v[Root(x)];
    }
    class LIB_UnionFind : LIB_UnionFind<int>
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_UnionFind(long n) : base(Enumerable.Repeat(0, (int)n), (x, y) => x + y) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        new private void Calc(long x) { }
    }
    class LIB_PriorityQueue
    {
        public long[] heap;
        public int[] dat;
        public long Count
        {
            get;
            private set;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue()
        {
            heap = new long[163];
            dat = new int[163];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(long key, int val)
        {
            if (Count == heap.Length) Expand();
            var i = Count++;
            heap[i] = key;
            dat[i] = val;
            while (i > 0)
            {
                var ni = (i - 1) / 2;
                if (key <= heap[ni]) break;
                heap[i] = heap[ni];
                dat[i] = dat[ni];
                i = ni;
            }
            heap[i] = key;
            dat[i] = val;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public KeyValuePair<long, int> Pop()
        {
            var ret = new KeyValuePair<long, int>(heap[0], dat[0]);
            var key = heap[--Count];
            var val = dat[Count];
            if (Count == 0) return ret;
            var i = 0; while ((i << 1) + 1 < Count)
            {
                var i1 = (i << 1) + 1;
                var i2 = (i << 1) + 2;
                if (i2 < Count && heap[i1] < heap[i2]) i1 = i2;
                if (key >= heap[i1]) break;
                heap[i] = heap[i1];
                dat[i] = dat[i1];
                i = i1;
            }
            heap[i] = key;
            dat[i] = val;
            return ret;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void Expand()
        {
            var tmp = new long[Count << 1];
            for (var i = 0; i < heap.Length; ++i) tmp[i] = heap[i];
            heap = tmp;
            var tmp2 = new int[Count << 1];
            for (var i = 0; i < dat.Length; ++i) tmp2[i] = dat[i];
            dat = tmp2;
        }
    }
    class LIB_PriorityQueue<T>
    {
        T[] heap;
        Comparison<T> comp;
        public T Peek => heap[0];
        public long Count
        {
            get;
            private set;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, Comparison<T> cmp, bool asc = true)
        {
            heap = new T[cap];
            comp = asc ? cmp : (x, y) => cmp(y, x);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(Comparison<T> cmp, bool asc = true)
        {
            heap = new T[16384];
            comp = asc ? cmp : (x, y) => cmp(y, x);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, bool asc = true) : this(cap, Comparer<T>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(bool asc = true) : this(Comparer<T>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(T val)
        {
            if (Count == heap.Length) Expand();
            var i = Count++;
            heap[i] = val;
            while (i > 0)
            {
                var ni = (i - 1) / 2;
                if (comp(val, heap[ni]) >= 0) break;
                heap[i] = heap[ni];
                i = ni;
            }
            heap[i] = val;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public T Pop()
        {
            var ret = heap[0];
            var val = heap[--Count];
            if (Count == 0) return ret;
            var i = 0; while ((i << 1) + 1 < Count)
            {
                var i1 = (i << 1) + 1;
                var i2 = (i << 1) + 2;
                if (i2 < Count && comp(heap[i1], heap[i2]) > 0) i1 = i2;
                if (comp(val, heap[i1]) <= 0) break;
                heap[i] = heap[i1]; i = i1;
            }
            heap[i] = val;
            return ret;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void Expand()
        {
            var tmp = new T[Count << 1];
            for (var i = 0; i < heap.Length; ++i) tmp[i] = heap[i];
            heap = tmp;
        }
    }
    class LIB_PriorityQueue<TK, TV>
    {
        LIB_PriorityQueue<KeyValuePair<TK, TV>> q;
        public KeyValuePair<TK, TV> Peek => q.Peek;
        public long Count => q.Count;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, Comparison<TK> cmp, bool asc = true)
        {
            q = new LIB_PriorityQueue<KeyValuePair<TK, TV>>(cap, (x, y) => cmp(x.Key, y.Key), asc);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(Comparison<TK> cmp, bool asc = true)
        {
            q = new LIB_PriorityQueue<KeyValuePair<TK, TV>>((x, y) => cmp(x.Key, y.Key), asc);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, bool asc = true) : this(cap, Comparer<TK>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(TK k, TV v) => q.Push(new KeyValuePair<TK, TV>(k, v));
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public KeyValuePair<TK, TV> Pop() => q.Pop();
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ProblemD
    {
        static bool SAIKI = false;
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = (int)NN;
            var m = (int)NN;
            var q = (int)NN;
            var pList = NNList(n);
            var ab = Repeat(0, m).Select(_ => new { a = (int)NN - 1, b = (int)NN - 1 }).ToArray();
            var query = Repeat(0, q).Select(_ => new { t = (int)NN, param = (int)NN }).ToArray();
            var graph = Repeat(0, n).Select(_ => new List<int>()).ToArray();
            var uf = new LIB_UnionFind(n);
            var deleted = new bool[m];
            foreach (var item in query)
            {
                if (item.t == 2) deleted[item.param - 1] = true;
            }
            var procTgtEdgeIndex = new bool[m];
            for (var i = 0; i < m; i++)
            {
                if (!deleted[i])
                {
                    if (uf.Unite(ab[i].a, ab[i].b))
                    {
                        graph[ab[i].a].Add(ab[i].b);
                        graph[ab[i].b].Add(ab[i].a);
                    }
                }
            }
            foreach (var item in query.Reverse())
            {
                if (item.t == 2)
                {
                    var i = item.param - 1;
                    if (uf.Unite(ab[i].a, ab[i].b))
                    {
                        procTgtEdgeIndex[i] = true;
                        graph[ab[i].a].Add(ab[i].b);
                        graph[ab[i].b].Add(ab[i].a);
                    }
                }
            }
            var param = new int[n];
            var qList = new List<LIB_PriorityQueue>();
            var used = new bool[n];
            {
                var done = new bool[n];
                for (var i = 0; i < n; i++)
                {
                    if (!done[i])
                    {
                        var c = qList.Count();
                        var tmpq = new LIB_PriorityQueue();
                        qList.Add(tmpq);
                        var que = new Queue<int>();
                        que.Enqueue(i);
                        done[i] = true;
                        param[i] = c;
                        while (que.Count > 0)
                        {
                            var v = que.Dequeue();
                            foreach (var item in graph[v])
                            {
                                if (done[item]) continue;
                                done[item] = true;
                                param[item] = c;
                                que.Enqueue(item);
                            }
                        }
                    }
                    qList[param[i]].Push((int)pList[i], i);
                }
            }
            foreach (var item in query)
            {
                if (item.t == 1)
                {
                    var v = item.param - 1;
                    var p = param[v];
                    var que = qList[p];
                    var value = 0L;
                    while (que.Count > 0)
                    {
                        if (used[que.Peek.Item2] || p != param[que.Peek.Item2]) que.Pop();
                        else
                        {
                            used[que.Peek.Item2] = true;
                            value = que.Pop().Key;
                            break;
                        }
                    }
                    Console.WriteLine(value);
                }
                else
                {
                    var leftV = ab[item.param - 1].a;
                    var rightV = ab[item.param - 1].b;
                    if (!procTgtEdgeIndex[item.param - 1]) continue;
                    var leftQ = new Queue<(int, int)>();
                    var rightQ = new Queue<(int, int)>();
                    var color = param[leftV];
                    var procV = leftV;
                    var lidx = 0;
                    var ridx = 0;
                    var lv = leftV;
                    var rv = rightV;
                    var lp = rightV;
                    var rp = leftV;
                    var exit = false;
                    while (true)
                    {
                        var leftOK = false;
                        while (true)
                        {
                            while (graph[lv].Count > lidx)
                            {
                                var v = graph[lv][lidx++];
                                if (v == lp) continue;
                                leftQ.Enqueue((v, lv));
                                leftOK = true;
                                break;
                            }
                            if (leftOK) break;
                            if (leftQ.Count == 0)
                            {
                                exit = true;
                                break;
                            }
                            var pop = leftQ.Dequeue();
                            lv = pop.Item1;
                            lp = pop.Item2;
                            lidx = 0;
                        }
                        if (exit) break;
                        var rightOK = false;
                        while (true)
                        {
                            while (graph[rv].Count > ridx)
                            {
                                var v = graph[rv][ridx++];
                                if (v == rp) continue;
                                rightQ.Enqueue((v, rv));
                                rightOK = true;
                                break;
                            }
                            if (rightOK) break;
                            if (rightQ.Count == 0)
                            {
                                procV = rightV;
                                exit = true;
                                break;
                            }
                            var pop = rightQ.Dequeue();
                            rv = pop.Item1;
                            rp = pop.Item2;
                            ridx = 0;
                        }
                        if (exit) break;
                    }
                    var procColorFrom = param[procV];
                    var procColorTo = qList.Count;
                    var tmpq = new LIB_PriorityQueue();
                    qList.Add(tmpq);
                    var procQ = new Queue<int>();
                    procQ.Enqueue(procV);
                    var done = new bool[n];
                    done[leftV] = true;
                    done[rightV] = true;
                    tmpq.Push((int)pList[procV], procV);
                    param[procV] = procColorTo;
                    while (procQ.Count > 0)
                    {
                        foreach (var item2 in graph[procQ.Dequeue()])
                        {
                            if (done[item2]) continue;
                            if (param[item2] != procColorFrom) continue;
                            if (!used[item2]) tmpq.Push((int)pList[item2], item2);
                            param[item2] = procColorTo;
                            done[item2] = true;
                            procQ.Enqueue(item2);
                        }
                    }
                }
            }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector);
        static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
        static bool Chmax<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) < 0) { lhs = rhs; return true; } return false; }
        static bool Chmin<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) > 0) { lhs = rhs; return true; } return false; }
    }
}
namespace Library {
    class LIB_FastIO
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[2048];
        int len, ptr;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        byte read()
        {
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 2048)) <= 0)
                {
                    return 0;
                }
            }
            return buf[ptr++];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = (ret << 3) + (ret << 1) + b - '0';
            }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIODebug() { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string Scan() => NextString();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override long Long() => long.Parse(NextString());
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override double Double() => double.Parse(NextString());
    }
    class LIB_UnionFind<T>
    {
        int[] d;
        T[] v;
        Func<T, T, T> f;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_UnionFind(IEnumerable<T> s, Func<T, T, T> func)
        {
            v = s.ToArray();
            d = Enumerable.Repeat(-1, v.Length).ToArray();
            f = func;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Unite(long x, long y)
        {
            x = Root(x);
            y = Root(y);
            if (x != y)
            {
                d[x] = d[x] + d[y];
                v[x] = f(v[x], v[y]);
                d[y] = (int)x;
            }
            return x != y;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool IsSame(long x, long y) => Root(x) == Root(y);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public long Root(long x) => d[x] < 0 ? x : d[x] = (int)Root(d[x]);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public long Count(long x) => -d[Root(x)];
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public T Calc(long x) => v[Root(x)];
    }
    class LIB_UnionFind : LIB_UnionFind<int>
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_UnionFind(long n) : base(Enumerable.Repeat(0, (int)n), (x, y) => x + y) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        new private void Calc(long x) { }
    }
    class LIB_PriorityQueue
    {
        long[] heap;
        int[] dat;
        public (long, int) Peek => (heap[0], dat[0]);
        public long Count
        {
            get;
            private set;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue()
        {
            heap = new long[128];
            dat = new int[128];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(long key, int val)
        {
            if (Count == heap.Length) Expand();
            var i = Count++;
            heap[i] = key;
            dat[i] = val;
            while (i > 0)
            {
                var ni = (i - 1) / 2;
                if (key <= heap[ni]) break;
                heap[i] = heap[ni];
                dat[i] = dat[ni];
                i = ni;
            }
            heap[i] = key;
            dat[i] = val;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public KeyValuePair<long, int> Pop()
        {
            var ret = new KeyValuePair<long, int>(heap[0], dat[0]);
            var key = heap[--Count];
            var val = dat[Count];
            if (Count == 0) return ret;
            var i = 0; while ((i << 1) + 1 < Count)
            {
                var i1 = (i << 1) + 1;
                var i2 = (i << 1) + 2;
                if (i2 < Count && heap[i1] < heap[i2]) i1 = i2;
                if (key >= heap[i1]) break;
                heap[i] = heap[i1];
                dat[i] = dat[i1];
                i = i1;
            }
            heap[i] = key;
            dat[i] = val;
            return ret;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void Expand()
        {
            var tmp = new long[Count << 1];
            for (var i = 0; i < heap.Length; ++i) tmp[i] = heap[i];
            heap = tmp;
            var tmp2 = new int[Count << 1];
            for (var i = 0; i < dat.Length; ++i) tmp2[i] = dat[i];
            dat = tmp2;
        }
    }
    class LIB_PriorityQueue<T>
    {
        T[] heap;
        Comparison<T> comp;
        public T Peek => heap[0];
        public long Count
        {
            get;
            private set;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, Comparison<T> cmp, bool asc = true)
        {
            heap = new T[cap];
            comp = asc ? cmp : (x, y) => cmp(y, x);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(Comparison<T> cmp, bool asc = true)
        {
            heap = new T[128];
            comp = asc ? cmp : (x, y) => cmp(y, x);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, bool asc = true) : this(cap, Comparer<T>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(bool asc = true) : this(Comparer<T>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(T val)
        {
            if (Count == heap.Length) Expand();
            var i = Count++;
            heap[i] = val;
            while (i > 0)
            {
                var ni = (i - 1) / 2;
                if (comp(val, heap[ni]) >= 0) break;
                heap[i] = heap[ni];
                i = ni;
            }
            heap[i] = val;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public T Pop()
        {
            var ret = heap[0];
            var val = heap[--Count];
            if (Count == 0) return ret;
            var i = 0; while ((i << 1) + 1 < Count)
            {
                var i1 = (i << 1) + 1;
                var i2 = (i << 1) + 2;
                if (i2 < Count && comp(heap[i1], heap[i2]) > 0) i1 = i2;
                if (comp(val, heap[i1]) <= 0) break;
                heap[i] = heap[i1]; i = i1;
            }
            heap[i] = val;
            return ret;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void Expand()
        {
            var tmp = new T[Count << 1];
            for (var i = 0; i < heap.Length; ++i) tmp[i] = heap[i];
            heap = tmp;
        }
    }
    class LIB_PriorityQueue<TK, TV>
    {
        LIB_PriorityQueue<KeyValuePair<TK, TV>> q;
        public KeyValuePair<TK, TV> Peek => q.Peek;
        public long Count => q.Count;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, Comparison<TK> cmp, bool asc = true)
        {
            q = new LIB_PriorityQueue<KeyValuePair<TK, TV>>(cap, (x, y) => cmp(x.Key, y.Key), asc);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(Comparison<TK> cmp, bool asc = true)
        {
            q = new LIB_PriorityQueue<KeyValuePair<TK, TV>>((x, y) => cmp(x.Key, y.Key), asc);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, bool asc = true) : this(cap, Comparer<TK>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(TK k, TV v) => q.Push(new KeyValuePair<TK, TV>(k, v));
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public KeyValuePair<TK, TV> Pop() => q.Pop();
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ProblemD
    {
        static bool SAIKI = false;
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = (int)NN;
            var m = (int)NN;
            var q = (int)NN;
            var pList = NNList(n);
            var ab = Repeat(0, m).Select(_ => new { a = (int)NN - 1, b = (int)NN - 1 }).ToArray();
            var query = Repeat(0, q).Select(_ => new { t = (int)NN, param = (int)NN }).ToArray();
            var graph = Repeat(0, n).Select(_ => new HashSet<int>()).ToArray();
            var uf = new LIB_UnionFind(n);
            var deleted = new bool[m];
            foreach (var item in query)
            {
                if (item.t == 2) deleted[item.param - 1] = true;
            }
            for (var i = 0; i < m; i++)
            {
                if (!deleted[i])
                {
                    if (uf.Unite(ab[i].a, ab[i].b))
                    {
                        graph[ab[i].a].Add(ab[i].b);
                        graph[ab[i].b].Add(ab[i].a);
                    }
                }
            }
            foreach (var item in query.Reverse())
            {
                if (item.t == 2)
                {
                    var i = item.param - 1;
                    if (uf.Unite(ab[i].a, ab[i].b))
                    {
                        graph[ab[i].a].Add(ab[i].b);
                        graph[ab[i].b].Add(ab[i].a);
                    }
                }
            }
            var param = new int[n];
            var qList = new List<LIB_PriorityQueue<int, int>>();
            var used = new bool[n];
            {
                var done = new bool[n];
                for (var i = 0; i < n; i++)
                {
                    if (!done[i])
                    {
                        var c = qList.Count();
                        var tmpq = new LIB_PriorityQueue<int, int>(false);
                        qList.Add(tmpq);
                        var que = new Queue<int>();
                        que.Enqueue(i);
                        done[i] = true;
                        param[i] = c;
                        while (que.Count > 0)
                        {
                            var v = que.Dequeue();
                            foreach (var item in graph[v])
                            {
                                if (done[item]) continue;
                                done[item] = true;
                                param[item] = c;
                                que.Enqueue(item);
                            }
                        }
                    }
                    qList[param[i]].Push((int)pList[i], i);
                }
            }
            foreach (var item in query)
            {
                if (item.t == 1)
                {
                    var v = item.param - 1;
                    var p = param[v];
                    var que = qList[p];
                    var value = 0L;
                    while (que.Count > 0)
                    {
                        if (used[que.Peek.Value] || p != param[que.Peek.Value]) que.Pop();
                        else
                        {
                            used[que.Peek.Value] = true;
                            value = que.Pop().Key;
                            break;
                        }
                    }
                    Console.WriteLine(value);
                }
                else
                {
                    var leftV = ab[item.param - 1].a;
                    var rightV = ab[item.param - 1].b;
                    if (!graph[leftV].Contains(rightV)) continue;
                    var leftQ = new Queue<int>();
                    var rightQ = new Queue<int>();
                    leftQ.Enqueue(leftV);
                    rightQ.Enqueue(rightV);
                    var color = param[leftV];
                    var procV = leftV;
                    var done = new bool[n];
                    done[leftV] = true;
                    done[rightV] = true;
                    while (true)
                    {
                        if (leftQ.Count == 0) break;
                        if (rightQ.Count == 0)
                        {
                            procV = rightV;
                            break;
                        }
                        foreach (var item2 in graph[leftQ.Dequeue()])
                        {
                            if (done[item2]) continue;
                            if (param[item2] != color) continue;
                            done[item2] = true;
                            leftQ.Enqueue(item2);
                        }
                        foreach (var item2 in graph[rightQ.Dequeue()])
                        {
                            if (done[item2]) continue;
                            if (param[item2] != color) continue;
                            done[item2] = true;
                            rightQ.Enqueue(item2);
                        }
                    }
                    var procColorFrom = param[procV];
                    var procColorTo = qList.Count;
                    var tmpq = new LIB_PriorityQueue<int, int>(false);
                    qList.Add(tmpq);
                    var procQ = new Queue<int>();
                    procQ.Enqueue(procV);
                    done = new bool[n];
                    done[leftV] = true;
                    done[rightV] = true;
                    tmpq.Push((int)pList[procV], procV);
                    param[procV] = procColorTo;
                    while (procQ.Count > 0)
                    {
                        foreach (var item2 in graph[procQ.Dequeue()])
                        {
                            if (done[item2]) continue;
                            if (param[item2] != procColorFrom) continue;
                            if (!used[item2]) tmpq.Push((int)pList[item2], item2);
                            param[item2] = procColorTo;
                            done[item2] = true;
                            procQ.Enqueue(item2);
                        }
                    }
                }
            }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector);
        static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
        static bool Chmax<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) < 0) { lhs = rhs; return true; } return false; }
        static bool Chmin<T>(this ref T lhs, T rhs) where T : struct, IComparable<T> { if (lhs.CompareTo(rhs) > 0) { lhs = rhs; return true; } return false; }
    }
}
namespace Library {
    class LIB_FastIO
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[2048];
        int len, ptr;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        byte read()
        {
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 2048)) <= 0)
                {
                    return 0;
                }
            }
            return buf[ptr++];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = (ret << 3) + (ret << 1) + b - '0';
            }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIODebug() { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string Scan() => NextString();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override long Long() => long.Parse(NextString());
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override double Double() => double.Parse(NextString());
    }
    class LIB_UnionFind<T>
    {
        int[] d;
        T[] v;
        Func<T, T, T> f;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_UnionFind(IEnumerable<T> s, Func<T, T, T> func)
        {
            v = s.ToArray();
            d = Enumerable.Repeat(-1, v.Length).ToArray();
            f = func;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Unite(long x, long y)
        {
            x = Root(x);
            y = Root(y);
            if (x != y)
            {
                d[x] = d[x] + d[y];
                v[x] = f(v[x], v[y]);
                d[y] = (int)x;
            }
            return x != y;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool IsSame(long x, long y) => Root(x) == Root(y);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public long Root(long x) => d[x] < 0 ? x : d[x] = (int)Root(d[x]);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public long Count(long x) => -d[Root(x)];
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public T Calc(long x) => v[Root(x)];
    }
    class LIB_UnionFind : LIB_UnionFind<int>
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_UnionFind(long n) : base(Enumerable.Repeat(0, (int)n), (x, y) => x + y) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        new private void Calc(long x) { }
    }
    class LIB_PriorityQueue
    {
        long[] heap;
        int[] dat;
        public long Count
        {
            get;
            private set;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue()
        {
            heap = new long[16384];
            dat = new int[16384];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(long key, int val)
        {
            if (Count == heap.Length) Expand();
            var i = Count++;
            heap[i] = key;
            dat[i] = val;
            while (i > 0)
            {
                var ni = (i - 1) / 2;
                if (key >= heap[ni]) break;
                heap[i] = heap[ni];
                dat[i] = dat[ni];
                i = ni;
            }
            heap[i] = key;
            dat[i] = val;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public KeyValuePair<long, int> Pop()
        {
            var ret = new KeyValuePair<long, int>(heap[0], dat[0]);
            var key = heap[--Count];
            var val = dat[Count];
            if (Count == 0) return ret;
            var i = 0; while ((i << 1) + 1 < Count)
            {
                var i1 = (i << 1) + 1;
                var i2 = (i << 1) + 2;
                if (i2 < Count && heap[i1] > heap[i2]) i1 = i2;
                if (key <= heap[i1]) break;
                heap[i] = heap[i1];
                dat[i] = dat[i1];
                i = i1;
            }
            heap[i] = key;
            dat[i] = val;
            return ret;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void Expand()
        {
            var tmp = new long[Count << 1];
            for (var i = 0; i < heap.Length; ++i) tmp[i] = heap[i];
            heap = tmp;
            var tmp2 = new int[Count << 1];
            for (var i = 0; i < dat.Length; ++i) tmp2[i] = dat[i];
            dat = tmp2;
        }
    }
    class LIB_PriorityQueue<T>
    {
        T[] heap;
        Comparison<T> comp;
        public T Peek => heap[0];
        public long Count
        {
            get;
            private set;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, Comparison<T> cmp, bool asc = true)
        {
            heap = new T[cap];
            comp = asc ? cmp : (x, y) => cmp(y, x);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(Comparison<T> cmp, bool asc = true)
        {
            heap = new T[16384];
            comp = asc ? cmp : (x, y) => cmp(y, x);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, bool asc = true) : this(cap, Comparer<T>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(bool asc = true) : this(Comparer<T>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(T val)
        {
            if (Count == heap.Length) Expand();
            var i = Count++;
            heap[i] = val;
            while (i > 0)
            {
                var ni = (i - 1) / 2;
                if (comp(val, heap[ni]) >= 0) break;
                heap[i] = heap[ni];
                i = ni;
            }
            heap[i] = val;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public T Pop()
        {
            var ret = heap[0];
            var val = heap[--Count];
            if (Count == 0) return ret;
            var i = 0; while ((i << 1) + 1 < Count)
            {
                var i1 = (i << 1) + 1;
                var i2 = (i << 1) + 2;
                if (i2 < Count && comp(heap[i1], heap[i2]) > 0) i1 = i2;
                if (comp(val, heap[i1]) <= 0) break;
                heap[i] = heap[i1]; i = i1;
            }
            heap[i] = val;
            return ret;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        void Expand()
        {
            var tmp = new T[Count << 1];
            for (var i = 0; i < heap.Length; ++i) tmp[i] = heap[i];
            heap = tmp;
        }
    }
    class LIB_PriorityQueue<TK, TV>
    {
        LIB_PriorityQueue<KeyValuePair<TK, TV>> q;
        public KeyValuePair<TK, TV> Peek => q.Peek;
        public long Count => q.Count;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, Comparison<TK> cmp, bool asc = true)
        {
            q = new LIB_PriorityQueue<KeyValuePair<TK, TV>>(cap, (x, y) => cmp(x.Key, y.Key), asc);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(Comparison<TK> cmp, bool asc = true)
        {
            q = new LIB_PriorityQueue<KeyValuePair<TK, TV>>((x, y) => cmp(x.Key, y.Key), asc);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(long cap, bool asc = true) : this(cap, Comparer<TK>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_PriorityQueue(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Push(TK k, TV v) => q.Push(new KeyValuePair<TK, TV>(k, v));
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public KeyValuePair<TK, TV> Pop() => q.Pop();
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    static List<List<int>> g;

    class Dsu
    {
        public readonly List<int> parent;

        public Dsu(int n)
        {
            parent = Enumerable.Range(0, n).ToList();
            g = Init<List<int>>(n).ToList();
        }

        public int FindSet(int v)
        {
            if (v == parent[v])
                return v;
            return parent[v] = FindSet(parent[v]);
        }

        public void UnionSets(int a, int b)
        {
            a = FindSet(a);
            b = FindSet(b);
            if (a != b)
            {
                parent[a] = parent[b] = parent.Count;
                g.Add(new List<int>());
                g[parent.Count].Add(a);
                g[parent.Count].Add(b);
                parent.Add(parent.Count);
            }
        }
    }

    int[] c;
    int[] tree;

    int Cmp(int l, int r)
    {
        return c2[l] > c2[r] ? l : r;
    }

    void Build(int x, int xl, int xr)
    {
        if (xl == xr)
        {
            tree[x] = xl;
            return;
        }
        int xm = (xl + xr) / 2;
        Build(x * 2, xl, xm);
        Build(x * 2 + 1, xm + 1, xr);
        tree[x] = Cmp(tree[2 * x], tree[2 * x + 1]);
    }

    void Set(int x, int xl, int xr, int idx)
    {
        if (xl == xr)
        {
            c2[xl] = 0;
            return;
        }

        int xm = (xl + xr) / 2;
        if (idx <= xm)
            Set(x * 2, xl, xm, idx);
        else
            Set(x * 2 + 1, xm + 1, xr, idx);
        tree[x] = Cmp(tree[2 * x], tree[2 * x + 1]);
    }

    int Query(int x, int xl, int xr, int l, int r)
    {
        if (l == xl && r == xr)
            return tree[x];
        int xm = (xl + xr) / 2;
        if (r <= xm)
            return Query(x * 2, xl, xm, l, r);
        if (l > xm)
            return Query(x * 2 + 1, xm + 1, xr, l, r);
        return Cmp(Query(x * 2, xl, xm, l, xm), Query(x * 2 + 1, xm + 1, xr, xm + 1, r));
    }

    int n;
    bool[] vis;
    int[] tin, tout, c2;
    int timer;
    void Dfs(int x)
    {
        if (x < n)
            c2[timer] = c[x];
        vis[x] = true;
        tin[x] = timer++;
        foreach (int e in g[x])
            Dfs(e);
        tout[x] = timer;
    }

    public void Solve()
    {
        n = ReadInt();
        int m = ReadInt();
        int q = ReadInt();
        c = ReadIntArray();
        var a = ReadIntMatrix(m);
        var b = ReadIntMatrix(q);

        var f = new bool[m];
        for (int i = 0; i < q; i++)
        {
            b[i][1]--;
            if (b[i][0] == 2)
                f[b[i][1]] = true;
        }

        var dsu = new Dsu(n);
        for (int i = 0; i < m; i++)
        {
            a[i][0]--;
            a[i][1]--;
            if (!f[i])
                dsu.UnionSets(a[i][0], a[i][1]);
        }

        for (int i = q - 1; i >= 0; i--)
        {
            if (b[i][0] == 1)
            {
                b[i][1] = dsu.FindSet(b[i][1]);
            }
            else
            {
                dsu.UnionSets(a[b[i][1]][0], a[b[i][1]][1]);
            }
        }

        int n2 = dsu.parent.Count;
        tin = new int[n2];
        tout = new int[n2];
        vis = new bool[n2];
        c2 = new int[n2];
        for (int i = n2 - 1; i >= 0; i--)
            if (!vis[i])
                Dfs(i);

        tree = new int[4 * n2];
        Build(1, 0, n2 - 1);
        for (int i = 0; i < q; i++)
            if (b[i][0] == 1)
            {
                int x = Query(1, 0, n2 - 1, tin[b[i][1]], tout[b[i][1]] - 1);
                Write(c2[x]);
                Set(1, 0, n2 - 1, x);
            }
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    static List<List<int>> g;

    class Dsu
    {
        public readonly List<int> parent;

        public Dsu(int n)
        {
            parent = Enumerable.Range(0, n).ToList();
            g = Init<List<int>>(n).ToList();
        }

        public int FindSet(int v)
        {
            if (v == parent[v])
                return v;
            return parent[v] = FindSet(parent[v]);
        }

        public void UnionSets(int a, int b)
        {
            a = FindSet(a);
            b = FindSet(b);
            if (a != b)
            {
                parent[a] = parent[b] = parent.Count;
                g.Add(new List<int>());
                g[parent.Count].Add(a);
                g[parent.Count].Add(b);
                parent.Add(parent.Count);
            }
        }
    }

    int[] c;
    int[] tree;

    int Cmp(int l, int r)
    {
        return c2[l] > c2[r] ? l : r;
    }

    void Build(int x, int xl, int xr)
    {
        if (xl == xr)
        {
            tree[x] = xl;
            return;
        }
        int xm = (xl + xr) / 2;
        Build(x * 2, xl, xm);
        Build(x * 2 + 1, xm + 1, xr);
        tree[x] = Cmp(tree[2 * x], tree[2 * x + 1]);
    }

    void Set(int x, int xl, int xr, int idx)
    {
        if (xl == xr)
        {
            c2[xl] = 0;
            return;
        }

        int xm = (xl + xr) / 2;
        if (idx <= xm)
            Set(x * 2, xl, xm, idx);
        else
            Set(x * 2 + 1, xm + 1, xr, idx);
        tree[x] = Cmp(tree[2 * x], tree[2 * x + 1]);
    }

    int Query(int x, int xl, int xr, int l, int r)
    {
        if (l == xl && r == xr)
            return tree[x];
        int xm = (xl + xr) / 2;
        if (r <= xm)
            return Query(x * 2, xl, xm, l, r);
        if (l > xm)
            return Query(x * 2 + 1, xm + 1, xr, l, r);
        return Cmp(Query(x * 2, xl, xm, l, xm), Query(x * 2 + 1, xm + 1, xr, xm + 1, r));
    }

    int n;
    bool[] vis;
    int[] tin, tout, c2;
    int timer;
    void Dfs(int x)
    {
        if (x < n)
            c2[timer] = c[x];
        vis[x] = true;
        tin[x] = timer++;
        foreach (int e in g[x])
            Dfs(e);
        tout[x] = timer;
    }

    public void Solve()
    {
        n = ReadInt();
        int m = ReadInt();
        int q = ReadInt();
        c = ReadIntArray();
        var a = ReadIntMatrix(m);
        var b = ReadIntMatrix(q);

        n = 200000;
        m = 199999;
        q = 500000;
        c = new int[n];
        var rnd = new Random(13);
        for (int i = 0; i < n; i++)
            c[i] = rnd.Next(n) + 1;
        a = new int[m][];
        for (int i = 0; i < m; i++)
            a[i] = new[] { i + 1, i + 2 };
        b = new int[q][];
        int cnt = 1;
        for (int i = 0; i < q; i++)
        {
            b[i] = new int[2];
            b[i][0] = rnd.Next(2) + 1;
            if (cnt > m)
                b[i][0] = 1;
            if (b[i][0] == 1)
            {
                b[i][1] = rnd.Next(n) + 1;
            }
            else
            {
                b[i][1] = cnt++;
            }
        }

        var f = new bool[m];
        for (int i = 0; i < q; i++)
        {
            b[i][1]--;
            if (b[i][0] == 2)
                f[b[i][1]] = true;
        }

        var dsu = new Dsu(n);
        for (int i = 0; i < m; i++)
        {
            a[i][0]--;
            a[i][1]--;
            if (!f[i])
                dsu.UnionSets(a[i][0], a[i][1]);
        }

        for (int i = q - 1; i >= 0; i--)
        {
            if (b[i][0] == 1)
            {
                b[i][1] = dsu.FindSet(b[i][1]);
            }
            else
            {
                dsu.UnionSets(a[b[i][1]][0], a[b[i][1]][1]);
            }
        }

        int n2 = dsu.parent.Count;
        tin = new int[n2];
        tout = new int[n2];
        vis = new bool[n2];
        c2 = new int[n2];
        for (int i = n2 - 1; i >= 0; i--)
            if (!vis[i])
                Dfs(i);

        tree = new int[4 * n2];
        Build(1, 0, n2 - 1);
        for (int i = 0; i < q; i++)
            if (b[i][0] == 1)
            {
                int x = Query(1, 0, n2 - 1, tin[b[i][1]], tout[b[i][1]] - 1);
                Write(c2[x]);
                Set(1, 0, n2 - 1, x);
            }
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            //new Solver().Solve();
            var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            thread.Start();
            thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}