import sys
import numpy as np

def input():
    return sys.stdin.readline().strip()

def main():
    n = int(input())
    a = list(map(np.int64, input().split()))
    q = int(input())
    ans = []
    for i in range(q):
        b, c = map(int, input().split())
        a = list(map(lambda x: c if x == b else x, a))
        ans.append(sum(a))

    for j in ans:
        print(j)

if __name__ == "__main__":
	main()