n = int(input(""))
s = list(map(int,input("").split()))
q = int(input(""))
for i in range(q):
    b_i, c_i = map(int,input("").split())
    for i in range(len(s)) :
        if s[i] == b_i:
           s[i] = c_i

    print(sum(s))
