read -r N
read -r S
read -r Q

#echo ${N} ${S} ${Q}

for c in $(echo ${S} | sed 's|\(.\)|\1 |g'); do
        echo ${c}
done > e.tmp

cnt=0
while [ ${Q} -gt ${cnt} ]; do
        read -r query
        #echo ${query}
        if [ 1 -eq $(echo ${query} | grep -e ^'1 ' | wc -l) ]; then
                i=$(echo ${query} | cut -d' ' -f2)
                c=$(echo ${query} | cut -d' ' -f3)
                sed -i "${i}s/./${c}/" e.tmp
        else
                l=$(echo ${query} | cut -d' ' -f2)
                r=$(echo ${query} | cut -d' ' -f3)
                head -n${r} e.tmp | tail -n$((${r} - ${l} + 1)) | sort | uniq | wc -l
        fi

        cnt=$((${cnt} + 1))
        #echo "==="
done