from sys import stdin

def main():
    n = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    q = int(input())
    for i in range(q):
        b, c = [int(x) for x in stdin.readline().rstrip().split()]
        a = [c if x == b else x for x in a]
        print(sum(a))

if __name__ == "__main__":
    main()