import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    ans = [0]*q
    for i in range(q):
        b,c = map(int, input().split())
        for j in range(n):
            if b == a_list[j]:
                a_list[j] = c
        ans[i] = sum(a_list)
        
    for i in ans:
        print(i)
   
if __name__ == "__main__":
    main()