N = int(input())	
A_list = list(map(int,input().split()))
Q = int(input())
result = []
while True:
    try:
        B, C = map(int,input().split())
        result.append([C if A == B else A for A in A_list])
    except:
        break

for i in result:
    print(sum(result))