
a = int(input())
s = list(map(int, input().split()))
q = int(input())


while q:
    c, d = map(int, input().split())
    # print(c, d)
    for i in range(len(s)):
        if s[i] == c:
            s[i] = d
    # print(s)
    print(sum(s))

    q -= 1
