if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B = []
    C = []

    for i in range(Q):
        b, c = map(int, input().split())
        B.append(b)
        C.append(c)
    for i, b in enumerate(B):
        for j, a in enumerate(A):
            if b==a:
                A[j]=C[i]
        print(sum(A))