# coding: utf-8
# Your code here!

N = int(input())
A = list(map(int,input().split()))
Q = int(input())

flg = False
for _ in range(Q):
    b,c = map(int,input().split())
    if(len(set(A))==1 and flg==False):
        flg = True
    if flg:
        B = A[0]
        if(B==b):
            # print('{}: {}'.format('A',c*N))
            print(c*N)
            A[0] = c
        else:
            print(B*N)
            # print('{}: {}'.format('B',B*N))
    else:
        A = [c if i == b else i for i in A]
        print(sum(A))
        # print('{}: {}'.format('C',sum(A)))