Module Module1

    Sub main()
        Dim user1 = Console.ReadLine()
        Dim suretsu As New List(Of Long)

        Dim user4 = Split(Console.ReadLine(), " ")
        Dim lista2 As Long() = Array.ConvertAll(user4, Function(j As String) CLng(j))
        suretsu = New List(Of Long)(lista2)

        '' A1...の取得
        'For i = 0 To CInt(user1) - 1
        '    Dim user2 = Split(Console.ReadLine(), " ")
        '    Dim lista As Long() = Array.ConvertAll(user2, Function(j As String) CLng(j))
        '    suretsu = New List(Of Long)(lista)
        'Next


        ' Q, B1...の取得
        Dim user3 = Console.ReadLine()
        Dim befNum As New List(Of Long), aftNum As New List(Of Long)

        For i = 0 To CInt(user3) - 1
            Dim user2 = Split(Console.ReadLine(), " ")
            Dim lista As Long() = Array.ConvertAll(user2, Function(j As String) CLng(j))
            Dim numlist = New List(Of Long)(lista)

            befNum.Add(numlist(0))
            aftNum.Add(numlist(1))
        Next

        ' 数値を置き換える
        For i = 0 To CLng(user3) - 1

            For j = 0 To suretsu.Count - 1
                If suretsu(j) = befNum(i) Then
                    suretsu(j) = aftNum(i)
                End If

                'suretsu.ForEach(
                'Sub(d)
                '    Console.WriteLine(d)
                'End Sub)
            Next
            Console.WriteLine(suretsu.Sum)
            'suretsu.ForEach(
            '    Sub(d)
            '        If d = befNum(i) Then
            '            suretsu(i) = aftNum(i)
            '            Console.WriteLine("REPLACE = > " & d)
            '        End If

            '    End Sub)
        Next
    End Sub
end module