from sys import stdin

def main():
    n = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    base = sum(a)
    q = int(input())
    for i in range(q):
        b, c = [int(x) for x in stdin.readline().rstrip().split()]
        offset = c -b
        cnt = 0
        for i, aaa in enumerate(a):
            if aaa == b:
                a[i] = c
                cnt += 1
        base = base + offset*cnt
        print(base)
        

if __name__ == "__main__":
    main()