
def main():
    n = int(input())
    a = list(map(int, input().split(" ")))
    q = int(input())
    bc = []
    for _ in range(q):
        bc.append(list(map(int, input().split(" "))))
    for i in range(q):
        for j in range(n):
            if bc[i][0] == a[j]:
                a[j] = bc[i][1]
        print(sum(a))
        
    


if __name__ == "__main__":
    main()