n = int(input())
a = list(map(int, input().split()))
q = int(input())
result = []
for i in range(q):
    s = 0
    b = list(map(int, input().split()))
    for m, k in enumerate(a):
        if  k == b[0]:
            a[m] = b[1]
        s += a[m]
    print(s)