def resolve():
    N = int(input())
    A = list(input().split())
    ans = ','.join(A)

    Q = int(input())

    replaces = []
    for i in range(Q):
        pp, ss = input().split()
        replaces.append([pp, ss])

    for varcher in replaces:
        ans = ans.replace(varcher[0], varcher[1])
        print(sum(map(int, ans.split(','))))


resolve()