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

def main():
    b_l = []
    c_l = []
    for i in range(0, q):
        b, c = map(int, input().split())
        b_l.append(b)
        c_l.append(c)

    for j in range(0, len(b_l)):
        for i in range(0, len(a)):
            if b_l[j] == a[i]:
                a.pop(i)
                a.insert(i,c_l[j])
        print(sum(a))
main()