Option Explicit On

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s1 As String, s2 As String, s3 As String
        Dim v1 As String, v2 As String, v3 As String
        Dim i As Integer,  n As Integer, m As Integer

        n = Trim(TextBox1.Text)
        s1 = Trim(TextBox2.Text)
        s2 = Trim(TextBox3.Text)
        s3 = Trim(TextBox4.Text)

        m = 0

        For i = 1 To n
            v1 = Mid(s1, i, 1)
            v2 = Mid(s2, i, 1)
            v3 = Mid(s3, i, 1)

            If (v1 = v2) Then
                If (v2 <> v3) Then
                    m = m + 1
                End If
            Else
                If (v1 = v3) Then
                    m = m + 1
                Else
                    If (v2 = v3) Then
                        m = m + 1
                    Else
                        m = m + 2
                    End If
                End If
            End If
        Next i

        TextBox5.Text = m
    End Sub

End Class
