macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        s: chars,
        q: usize,
        qs: [(usize, usize1, String); q]
    }
    let mut sv = s.iter().map(|&c| cidx(c)).collect::<Vec<usize>>();
    let mut bits = vec![BIT::new(n + 1); 26];
    for i in 0..n {
        bits[sv[i]].add(i + 1, 1);
    }
    for q in &qs {
        if q.0 == 1 {
            let ci = cidx(q.2.chars().nth(0).unwrap());
            bits[sv[q.1]].add(q.1 + 1, -1);
            bits[ci].add(q.1 + 1, 1);
            sv[q.1] = ci;
        } else {
            let r = q.2.parse::<usize>().unwrap();
            let mut ans = 0;
            for i in 0..26 {
                if bits[i].sum(r) - bits[i].sum(q.1) > 0 {
                    ans += 1;
                }
            }
            println!("{}", ans);
        }
    }
}

fn cidx(c: char) -> usize {
    (c as u8 - 'a' as u8) as usize
}

#[derive(Clone)]
struct BIT {
    v: Vec<i64>,
    n: usize
}

impl BIT {
    fn new(n: usize) -> BIT {
        BIT{v: vec![0; n + 1], n: n}
    }

    fn add(&mut self, i: usize, x: i64) {
        let mut id = i as i64 + 1;
        while id <= self.n as i64 {
            self.v[id as usize] += x;
            id += id & -id;
        }
    }

    fn sum(&self, i: usize) -> i64 {
        let mut id = i + 1;
        let mut ret = 0;
        while id > 0 {
            ret += self.v[id];
            id &= id - 1;
        }
        ret
    }
}


Measured memory_bytes: 118136