using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Security.Cryptography;

namespace ABC171
{

    class D
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(" ");
            int[] A = new int[N];
            for(var i = 0; i< N;i++)
            {
                A[i] = int.Parse(input[i]);
            }
            int Q = int.Parse(Console.ReadLine());
            int[] B = new int[Q];
            int[] C = new int[Q];
            for(var i = 0; i<Q;i++)
            {
                string[] input2 = Console.ReadLine().Split(" ");
                B[i] = int.Parse(input2[0]);
                C[i] = int.Parse(input2[1]);
            }
            int[] S = new int[Q]; 
            for(var i = 0;i<Q; i++)
            {
                for(var j =0; j<A.Length; j++)
                {
                    if(A[j]==B[i])
                    {
                        A[j] = C[i];
                    }
                    S[i] = A.Sum();
                }
            }
            for(var k = 0; k< Q; k++)
            {
                Console.WriteLine(S[k]);
            }
        }
    }
}
