def Replacing():

    Num = int(input())

    value_A = list(map(int,input().split()))

    NumB = int(input())

    for i in range(NumB):
        value_B = list(map(int,input().split()))

        vb_0 = value_B[0]
        vb_1 = value_B[1]

        value_A = [vb_1 if j == vb_0 else j for j in value_A]

        print(sum(value_A))

if __name__ == '__main__':
    Replacing()
