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

  do i = 1, Q
     read(*,'(a,x,a,x,a)') a,b,c
     if (a == '1') then
        read(b(1:1),*) j
        S(j:j) = c
     else
        read(b(1:1),*) l
        read(c(1:1),*) r
        tmp = S(l:r)
        call count_char(tmp,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
       tmp = ichar(S(i:i))
       c (tmp) = c(tmp) + 1
    end do
    out = count(c /=0)
  end subroutine count_char
end program main
