{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString as BR
import qualified Data.ByteString.Char8 as B
import qualified Data.IntSet as IS
import qualified Data.ByteString.Internal as B
import Control.Monad
import Foreign.ForeignPtr
import Foreign.Storable
import qualified Data.IntMap.Strict as IM
import Data.IORef 

type Counter = IS.IntSet

data Builder = Builder !Int !Counter !(IM.IntMap Counter)

splitR :: Int -> IM.IntMap a -> (IM.IntMap a, IM.IntMap a)
splitR i m = let (l, p, r) = IM.splitLookup i m in (l, maybe id (IM.insert i) p r)

main = do
    _ <- B.getLine
    str <- B.getLine
    numQueries <- readLn
    let build (Builder i s m) c
            | IS.member c s = Builder (i + 1) s m
            | otherwise = let s' = IS.insert c s
                in Builder (i + 1) mempty (IM.insert i s' m)
    let Builder _ _ map0 = BR.foldl' (\b -> build b . fromEnum) (Builder 1 mempty mempty) str
    ref <- newIORef map0
    replicateM_ numQueries $ do
        [typ, p, q] <- B.words <$> B.getLine 
        case typ of
            "1" -> do
                base <- readIORef ref

                let i = read $ B.unpack p
                let v = BR.head q
                
                case IM.lookupGE i base of
                    Nothing -> pure ()
                    Just (k, s) -> writeIORef ref $! IM.insert k (IS.insert (fromEnum v) s) base
            "2" -> do
                base <- readIORef ref
                let i = read $ B.unpack p
                let j = read $ B.unpack q

                let (_, wing) = splitR i base
                let (body, _) = splitR (j + 1) wing
                print $ IS.size $ IS.unions $ IM.elems body