program main
  implicit none
  type arr_list
     integer :: N
     integer,allocatable :: point(:)
  end type arr_list
  type(arr_list),allocatable :: data(:)
  integer :: num(97:122)
  integer :: N, Q
  character(len=500000) :: S
  integer(1),allocatable :: S2(:)
  !character(:),allocatable :: tmp
  integer(1),allocatable :: tmp(:)
  character(len=1) :: c,b,c2
  integer :: a
  integer :: i,j, l,r
  integer :: out
  read(*,*) N
  read(*,*) S
  read(*,*) Q
  allocate(S2(N))
  do i = 1,N
     S2(i) =  ichar(S(i:i))
  end do
  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
        S2(j:j) = ichar(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)
        call count_char2(S2(l:r),out)
        write(*,'(i0)') out
        !deallocate(tmp)
     end if

  end do
contains
  subroutine count_char2(S,out)
    integer(1) :: S(:)
    integer :: out
    integer :: N
    integer :: i, tmp
    integer(1) :: c(97:122)
    N = size(S)
    c(97:122) = 0
!    do i = 1,N
!       c (S(i)) =  1
!    end do
    do i = 97,122
       if (any(S==i)) c(i) =  1
    end do
    out = count(c /=0)
  end subroutine count_char2
end program main
