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

namespace _27_9
{
    class Program
    {

        static void Main(string[] args)
        {
            int n,m,i,q,maxzl=0,br=0,imax=0,j,k;
            string[] s;
            n = int.Parse(Console.ReadLine());
            int[,]a=new int [n, 2];
            for(i=0;i<n-1;i++)
            {
                s = Console.ReadLine().Split(' ');
                a[i, 0] = int.Parse(s[0]);
                a[i, 1] = int.Parse(s[1]);
            }
            int[] zl = new int[n];
            s = Console.ReadLine().Split(' ');
            for(i=0;i<n;i++)
                zl[i]=int.Parse(s[i]);
            q = int.Parse(Console.ReadLine());
            int[,] pit = new int[q,2];
            for (i = 0; i < q; i++)
            {
                s = Console.ReadLine().Split(' ');
                pit[i, 0] = int.Parse(s[0]);
                pit[i, 1] = int.Parse(s[1]);
            }
            for(i=0;i<n;i++)
            {
                if (zl[i] > maxzl)
                {
                    maxzl = zl[i];
                    imax = i+1;
                }
                if (maxzl == zl[i])
                    br++;
            }
            if (br == n)
            {
                bool p = true;
                for(i=0;i<n-2;i++)
                {
                    if (a[i, 1] != a[i + 1, 0])
                        p = false;
                }
                if (p)
                    imax = n / 2 + 1;
            }
            else
            {
                for(k=n-1;k>=0;k--)
                {
                    if (zl[k] == maxzl)
                        imax = k + 1;
                }
            }
            Console.WriteLine("{0}", imax);
            for(i=0;i<q;i++)
            {
                zl[pit[i,1]-1] = pit[i,0];
                for (k = 0; k < n; k++)
                {
                    if (zl[k] > maxzl)
                    {
                        maxzl = zl[k];
                        imax = k+1;
                    }
                    if (maxzl == zl[k])
                        br++;
                }
                if (br == n)
                {
                    bool p = true;
                    for (k = 0; k < n - 2; k++)
                    {
                        if (a[k, 1] != a[k + 1, 0])
                            p = false;
                    }
                    if (p)
                        imax = n / 2 + 1;
                }
                else
                {
                    for (k = n - 1; k >= 0; k--)
                    {
                        if (zl[k] == maxzl)
                            imax = k + 1;
                    }
                }
                Console.WriteLine("{0}", imax);
            }
        }
    }
}