def solve():
    for i in range(len(arr)):
        if arr[i] == b:
            arr[i] = c
    return sum(arr)

if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    q = int(input())
    for i in range(q):
        b, c, = map(int, input().split())
        print(solve())