package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"math/bits"
	"os"
	"strconv"
)

var DEBUG = true

func merge(a, b int) int {
	return a | b
}

func main() {
	defer Flush()
	N := readi()
	S := readb()
	a := make([]int, N)
	for i := range S {
		a[i] = 1 << uint(S[i]-'a')
	}
	st := NewSegmentTree(a, 0, merge)

	Q := readi()
	for q := 0; q < Q; q++ {
		t := readi()
		if t == 1 {
			i := readi() - 1
			c := readb()[0]
			v := 1 << uint(c-'a')
			st.Update(i, v)
		} else {
			l := readi() - 1
			r := readi()
			v := st.GetRange(l, r)
			println(bits.OnesCount(uint(v)))
		}
	}

}

type SegmentTree struct {
	a     []int
	n     int
	base  int
	inf   int
	merge func(x, y int) int
}

func NewSegmentTree(a []int, inf int, merge func(x, y int) int) *SegmentTree {
	n := len(a)
	base := 1
	for base < n {
		base *= 2
	}
	aa := make([]int, base*2)
	//fmt.Fprintf(os.Stderr, "n:%d base:%d len(aa):%d\n", n, base, len(aa))
	for i := range a {
		//fmt.Fprintf(os.Stderr, "base+i:%d base:%d i:%d\n", base+i, base, i)
		aa[base+i] = a[i]
	}
	for i := base + n; i < len(aa); i++ {
		aa[i] = inf
	}

	for b := base; 1 < b; b /= 2 {
		for i := b; i < b*2; i += 2 {
			aa[i/2] = merge(aa[i], aa[i+1])
		}
	}

	//for b := 1; b <= base; b *= 2 {
	//	n := b
	//	fmt.Fprintf(os.Stderr, "base:%d %v\n", b, aa[b:b+n])
	//}
	//fmt.Fprintf(os.Stderr, "\n")

	return &SegmentTree{
		a:     aa,
		n:     n,
		base:  base,
		inf:   inf,
		merge: merge,
	}
}

func (st *SegmentTree) Update(i, v int) {
	//fmt.Fprintf(os.Stderr, "Update: %d %d\n", i, v)
	//for b := 1; b <= st.base; b *= 2 {
	//	n := b
	//	fmt.Fprintf(os.Stderr, "base:%d %v\n", b, st.a[b:b+n])
	//}
	//fmt.Fprintf(os.Stderr, "\n")
	st.a[st.base+i] = v
	for b := st.base + i; 1 < b; b /= 2 {
		//fmt.Fprintf(os.Stderr, "st.a[%d]=%d -> %d\n", b, st.a[b], v)
		p := b / 2
		j := p * 2
		k := p*2 + 1
		st.a[p] = st.merge(st.a[j], st.a[k])
	}
	//for b := 1; b <= st.base; b *= 2 {
	//	n := b
	//	fmt.Fprintf(os.Stderr, "base:%d %v\n", b, st.a[b:b+n])
	//}
	//fmt.Fprintf(os.Stderr, "\n")
}

func (st *SegmentTree) GetRange(l, r int) int {
	//fmt.Fprintf(os.Stderr, "GET RANGE %v l:%d r:%d\n", st.a[st.base:st.base+st.n], l, r)
	q := make([][2]int, 0)
	push := func(base, off int) {
		q = append(q, [2]int{base, off})
	}
	pop := func() (int, int) {
		res := q[0]
		q = q[1:]
		return res[0], res[1]
	}
	push(1, 0)

	res := st.inf
	for len(q) != 0 {
		base, off := pop()
		n := st.base / base
		cl := n * off
		cr := cl + n
		//fmt.Fprintf(os.Stderr, "base:%d off:%d cl:%d cr:%d l:%d r:%d\n", base, off, cl, cr, l, r)
		if r <= cl || cr <= l {
			continue
		}
		if l <= cl && cr <= r {
			//fmt.Fprintf(os.Stderr, "GOTCHA base:%d off:%d cl:%d cr:%d l:%d r:%d => (%d, %d) => %d\n", base, off, cl, cr, l, r, res, st.a[base+off], st.merge(res, st.a[base+off]))
			res = st.merge(res, st.a[base+off])
			continue
		}
		push(base*2, off*2)
		push(base*2, off*2+1)
	}
	//fmt.Fprintf(os.Stderr, "GET RANGE %v l:%d r:%d => %d\n", st.a[st.base:st.base+st.n], l, r, res)

	return res
}

// func (st *SegmentTree) FindTheIndex(l, r int) (int, int) {}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}


Measured memory_bytes: 28552