// macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
// macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
// macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
trait Monoid {
    type T: Clone + PartialEq;
    fn identity(&self) -> Self::T;
    fn binary_operate(&self, x: &Self::T, y: &Self::T) -> Self::T;
}
struct BinaryIndexedTree<M: Monoid> {
    bit: Vec<M::T>,
    monoid: M,
}
impl<M: Monoid> BinaryIndexedTree<M> {
    fn new(n: usize, monoid: M) -> BinaryIndexedTree<M> {
        let bit = vec![monoid.identity(); n + 1];
        BinaryIndexedTree {
            bit: bit,
            monoid: monoid,
        }
    }
    fn query(&self, k: usize) -> M::T {
        let mut res = self.monoid.identity();
        let mut k = k as isize + 1;
        while k > 0 {
            res = self.monoid.binary_operate(&res, &self.bit[k as usize]);
            k -= k & -k;
        }
        res
    }
    fn update(&mut self, k: usize, x: M::T) {
        let mut k = k as isize + 1;
        while k < self.bit.len() as isize {
            self.bit[k as usize] = self.monoid.binary_operate(&self.bit[k as usize], &x);
            k += k & -k;
        }
    }
}
struct AnyMonoid<T: Clone, F: Fn(&T, &T) -> T> {
    id: T,
    op: F,
}
impl<T: Clone, F: Fn(&T, &T) -> T> AnyMonoid<T, F> {
    fn new(id: T, op: F) -> AnyMonoid<T, F> {
        AnyMonoid { id: id, op: op }
    }
}
impl<T: Clone + PartialEq, F: Fn(&T, &T) -> T> Monoid for AnyMonoid<T, F> {
    type T = T;
    fn identity(&self) -> T {
        self.id.clone()
    }
    fn binary_operate(&self, x: &T, y: &T) -> T {
        (self.op)(x, y)
    }
}
fn main() {
    let ss = {
        use std::io::Read;
        let mut ss = String::new();
        std::io::stdin().read_to_string(&mut ss).unwrap();
        ss
    };
    let mut iter = ss.split_whitespace();
    // input_inner!{iter, $($r)*}
    let n = iter.next().unwrap().parse::<usize>().unwrap();
    let s = iter
        .next()
        .unwrap()
        .parse::<String>()
        .unwrap()
        .chars()
        .collect::<Vec<char>>();
    // input! { n, s: chars, q };
    let q = iter.next().unwrap().parse::<usize>().unwrap();
    let s = s
        .into_iter()
        .map(|x| (x as u8 - 'a' as u8) as usize)
        .collect::<Vec<_>>();
    let mut bits = vec![];
    for _i in 0..26 {
        bits.push(BinaryIndexedTree::new(
            n + 1,
            AnyMonoid::new(0isize, |&x, &y| x + y),
        ));
    }
    for i in 0..n {
        bits[s[i]].update(i + 1, 1);
    }
    for _i in 0..q {
        // input! {x};
        let x = iter.next().unwrap().parse::<usize>().unwrap();
        if x == 1 {
            let i = iter.next().unwrap().parse::<usize>().unwrap();
            let c = iter
                .next()
                .unwrap()
                .parse::<String>()
                .unwrap()
                .chars()
                .collect::<Vec<char>>()[0];
            // input! {i, c: char};
            for j in 0..26 {
                let m = bits[j].query(i) - bits[j].query(i - 1);
                bits[j].update(i, -m);
            }
            bits[(c as u8 - 'a' as u8) as usize].update(i, 1);
        } else {
            let mut res = 0;
            let l = iter.next().unwrap().parse::<usize>().unwrap();
            let r = iter.next().unwrap().parse::<usize>().unwrap();
            // input! {l,r};
            for j in 0..26 {
                let x = bits[j].query(r) as isize - bits[j].query(l - 1) as isize;
                if x > 0 {
                    res += 1;
                }
            }
            println!("{}", res);
        }
    }
}


Measured memory_bytes: 117492