#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

use std::ops::Range;
#[derive(Clone)]
struct BIT { size: usize, array: Vec<i32> }
impl BIT {
    fn new(n: usize) -> BIT {
        BIT  { size: n, array: vec![0; n + 1] }
    }
    fn add(&mut self, idx: usize, w: i32) {
        let mut x = idx + 1;
        while x <= self.size {
            self.array[x] += w;
            let xi = x as i32;
            x += (xi&-xi) as usize;
        }
    }
    fn sum_up(&self, idx: usize) -> i32 { // [0, idx)
        let mut sum = 0;
        let mut x = idx;
        while x > 0 {
            sum += self.array[x];
            let xi = x as i32;
            x -= (xi&-xi) as usize;
        }
        sum
    }
    fn sum(&self, range: Range<usize>) -> i32 {
        self.sum_up(range.end) - self.sum_up(range.start)
    }
}

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

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut s: Vec<usize> = sc.chars().iter().map(|&c| ord(c)).collect();

    let mut bits = vec![BIT::new(n) ; 26];
    for i in 0..n {
        let c = s[i];
        bits[c].add(i, 1);
    }

    let q: usize = sc.cin();
    for _ in 0..q {
        let ty: usize = sc.cin();
        if ty == 1 {
            let idx = sc.cin::<usize>() - 1;
            let c = ord(sc.chars()[0]);
            if s[idx] == c { continue }
            bits[s[idx]].add(idx, -1);
            bits[c].add(idx, 1);
            s[idx] = c;
        } else {
            let left: usize = sc.cin();
            let right: usize = sc.cin();
            let mut a = 0;
            for c in 0..26 {
                if bits[c].sum(left-1..right) > 0 {
                    a += 1;
                }
            }
            put!(a);
        }
    }

    trace!(n);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 60272