s = [input() for i in range(3)]
l0 = int(s[0])
l1 = list(map(int, s[1].split()))
l2 = int(s[2])
t = [input() for i in range(l2)]
for i in range(l2):
    m = list(map(int, t[i].split()))
    b = m[0]
    c = m[1]
    l1 = [c if j == b else j for j in l1]
    print(sum(l1))
