#![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;

/// Algebra - Monoid

trait Monoid: std::ops::Mul<Output=Self> + Clone + Copy {
    fn unit() -> Self;
}
impl Monoid for i64 { fn unit() -> Self { 0 }}
impl Monoid for f64 { fn unit() -> Self { 0.0 }}

trait Group: std::ops::Add<Output=Self> + std::ops::Sub<Output=Self> + std::ops::Neg<Output=Self>
    + std::iter::Sum + Clone + Copy {
    fn zero() -> Self;
}
impl Group for i32 { fn zero() -> Self { 0 }}
impl Group for i64 { fn zero() -> Self { 0 }}
impl Group for f32 { fn zero() -> Self { 0.0 }}
impl Group for f64 { fn zero() -> Self { 0.0 }}

trait Ring: Group + std::ops::Mul<Output=Self> + std::ops::Div<Output=Self> {
    fn one() -> Self;
}
impl Ring for i32 { fn one() -> Self { 1 }}
impl Ring for i64 { fn one() -> Self { 1 }}
impl Ring for f32 { fn one() -> Self { 1.0 }}
impl Ring for f64 { fn one() -> Self { 1.0 }}

/// Max/Min Int Monoid for RMQ

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
enum MaxInt { Minimal, Val(i64) }
impl std::ops::Mul for MaxInt {
    type Output = Self;
    fn mul(self, other: Self) -> Self {
        if self > other { self } else { other }
    }
}
impl Monoid for MaxInt {
    fn unit() -> Self { MaxInt::Minimal }
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
enum MinInt { Val(i64), Maximal }
impl std::ops::Mul for MinInt {
    type Output = Self;
    fn mul(self, other: Self) -> Self {
        if self < other { self } else { other }
    }
}
impl Monoid for MinInt {
    fn unit() -> Self { MinInt::Maximal }
}

#[derive(Clone)]
struct SegmentTree<T> { size: usize, depth: usize, data: Vec<Vec<T>> }
impl<T> std::ops::Index<usize> for SegmentTree<T> {
    type Output = T;
    fn index(&self, i: usize) -> &Self::Output {
        &self.data[self.depth - 1][i]
    }
}
impl<T: Monoid> SegmentTree<T> {
    fn new(size: usize) -> SegmentTree<T> {
        let mut data = vec![];
        let mut i = 1;
        loop {
            data.push(vec![T::unit(); i]);
            if i >= size { break }
            i *= 2;
        }
        SegmentTree { size: size, depth: data.len(), data: data }
    }
    fn to_vec(self) -> Vec<T> {
        (self.data[self.depth - 1][0..self.size]).to_vec()
    }
    fn update(&mut self, idx: usize, t: T) {
        self.data[self.depth - 1][idx] = t;
        let mut i = idx;
        for d in (0..self.depth - 1).rev() {
            i /= 2;
            self.data[d][i] = self.data[d + 1][i * 2] * self.data[d + 1][i * 2 + 1];
        }
    }
    fn product(&self, range: std::ops::Range<usize>) -> T {
        if range.end == 0 || range.start + 1 > range.end {
            T::unit()
        } else if range.start + 1 == range.end {
            self[range.start]
        } else {
            let mut i = range.start;
            let mut d = self.depth - 1;
            let mut width = 1;
            while d > 0 {
                let left = (i / 2) * width * 2;
                let right = left + width * 2;
                if left == range.start && right <= range.end {
                    i /= 2;
                    d -= 1;
                    width *= 2;
                } else {
                    break
                }
            }
            let right = range.start + width;
            self.data[d][i] * self.product(right..range.end)
        }
    }
}
impl<T: std::fmt::Debug> SegmentTree<T> {
    fn debug(&self) {
        for i in 0..self.depth {
            trace!(&self.data[i]);
        }
    }
}

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();

    use MaxInt::Val;

    let mut seqs: Vec<SegmentTree<MaxInt>> = vec![SegmentTree::new(n); 26];
    for i in 0..n {
        seqs[s[i]].update(i, Val(1));
    }

    let q: usize = sc.cin();
    for _ in 0..q {
        let ty: usize = sc.cin();
        if ty == 1 {
            let i = sc.cin::<usize>() - 1;
            let c: char = *sc.chars().iter().next().unwrap();
            let x = ord(c);
            if s[i] == x { continue }
            seqs[s[i]].update(i, Val(0));
            seqs[x].update(i, Val(1));
            s[i] = x;
        } else {
            let l: usize = sc.cin::<usize>() - 1;
            let r: usize = sc.cin::<usize>() - 1;
            let ans = (0..26).map(|i|
                seqs[i].product(l..r+1)
            ).map(|x| {
                if let Val(x) = x {
                    x
                } else {
                    0
                }
            }).sum::<i64>();
            put!(ans);
        }
    }

}

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: 436464