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(" ");
            long[] A = new long[N];
            for (var i = 0; i < N; i++)
            {
                A[i] = long.Parse(input[i]);
            }
            Array.Sort(A);
            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]);
            }
            long[] S = new long[Q];
            for (var i = 0; i < Q; i++)
            {
                for (var j = 0; j < N; j++)
                {
                    if(A[j]<B[i])
                    {
                        continue;
                    }
                    else if (A[j] == B[i])
                    {
                        A[j] = C[i];
                    }
                    else
                    {
                        break;
                    }
                    
                }
                S[i] = A.Sum();
            }
            for (var k = 0; k < Q; k++)
            {
                Console.WriteLine(S[k]);
            }
        }
    }
}
