using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramC a = new ProgramC();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            int D = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int n = 26;

            long[] c = new long[n];
            long[] count = new long[n];

            for (int i = 0; i < n; i++)
                c[i] = long.Parse(s[i]);

            long[,] score = new long[n, D];

            for (int i = 0; i < D; i++)
            {
                string[] t = Console.ReadLine().Split(' ');
                for (int j = 0; j < n; j++)
                    score[j, i] = long.Parse(t[j]);
            }

            //とりあえず、各日にちのスコアの最大値を選ぶ
            for (int i = 0; i < D; i++)
            {
                int max = 0;
                long max_s = score[0,i];
                for (int j = 1; j < n; j++)
                {
                    if (max_s < score[j,i])
                    {
                        max = j;
                        max_s = score[j,i];
                    }
                }

                Console.WriteLine(max + 1);
            }

        }
    }
    //ABC170
    class ProgramB
    {
        public void main()
        {
            //入力
            int D = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int n = 26;

            long[] c = new long[n];
            long[] count = new long[n];

            long[,] score = new long[n,D];

            for (int i = 0; i < D; i++)
            {
                string[] t = Console.ReadLine().Split(' ');
                for (int j = 0; j < n; j++)
                    score[j, i] = long.Parse(t[j]);
            }

            for (int i = 0; i < n; i++)
                c[i] = long.Parse(s[i]);

            long ans = 0;
            
            for (int i = 0;i < D;i++)
            {
                int v = int.Parse(Console.ReadLine());

                count[v-1] = i+1;
                long sum = score[v - 1, i];
                for(int j = 0;j < n;j++)
                {
                    if(j != v -1)
                        sum -= c[j] * (i + 1 - count[j]);
                }
                ans += sum;

                Console.WriteLine(ans);
            }

        }
    }

    

    class ProgramC
    {
        public void main()
        {
            //入力
            int D = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int n = 26;

            long[] c = new long[n];

            long[,] score = new long[n, D];
            int[] d = new int[D];

            for (int i = 0; i < D; i++)
            {
                string[] t = Console.ReadLine().Split(' ');
                for (int j = 0; j < n; j++)
                    score[j, i] = long.Parse(t[j]);
            }

            for (int i = 0; i < n; i++)
                c[i] = long.Parse(s[i]);


            for (int i = 0; i < D; i++)
                d[i] = int.Parse(Console.ReadLine()) - 1;
                

            //クエリのかず
            int m = int.Parse(Console.ReadLine());

            for (int i = 0; i < m; i++)
            {

                long[] count = new long[n];
                string[] q = Console.ReadLine().Split(' ');
                int old = d[int.Parse(q[0]) - 1];
                d[int.Parse(q[0]) - 1] = int.Parse(q[1]) - 1;
                long ans = 0;
                for (int j = 0; j < D; j++)
                {

                    count[d[j]]= j + 1;
                    long sum = score[d[j], j];
                    for (int k = 0; k < n; k++)
                    {
                        if (k != d[j])
                            sum -= c[k] * (j + 1 - count[k]);
                    }

                    ans += sum;
                }

                Console.WriteLine(ans);
                //d[int.Parse(q[0]) - 1] = old;

            }


        }
    }

    

}






Measured memory_bytes: 40340