program main
  implicit none
  integer :: N, Q
  character(len=500000) :: S
  character(:),allocatable :: tmp
  character(len=1) :: c,b
  integer :: a
  integer :: i,j, l,r
  integer :: out
  read(*,*) N
  read(*,*) S
  read(*,*) Q

  do i = 1, Q
     read(*,'(i1,1x,a,1x,a)') a,b,c
     
     if (a == 1) then
        backspace(5)
        !read(*,'(i1,1x,g0,1x,a)') a,j,c
        read(*,*) a,j,c
        S(j:j) = c
     else
        backspace(5)
!        read(*,'(i1,1x,g0,1x,g0)') a,l,r
        read(*,*) a,l,r
        !tmp = S(l:r)
        call count_char(S(l:r),out)
        write(*,'(i0)') out
        !deallocate(tmp)
     end if

  end do
contains
  subroutine count_char(S,out)
    character(*) :: S
    integer :: out
    integer :: N
    integer :: i, tmp
    integer :: c(97:122)
    N = len_trim(S)
    c(97:122) = 0
    do i = 1,N
       c (ichar(S(i:i))) =  1
    end do
    out = count(c /=0)
  end subroutine count_char
end program main
