def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    for _ in range(q):
        l = []
        b, c = map(int, input().split())
        for i in a:
            l.append(c) if i == b else l.append(i)
        print(sum(l))

        a = l[:]


if __name__ == "__main__":
    main()
