#[allow(unused_imports)]
use std::char::from_digit;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::fs::File;
#[allow(unused_imports)]
use std::io::prelude::*;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Stdin, Stdout, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

type BoxResult<T> = Result<T, Box<std::error::Error>>;

fn main() {
    let mut scanner = Scanner::new(stdin());
    let n = scanner.read::<usize>().unwrap();
    let s = scanner
        .read_chars()
        .unwrap()
        .into_iter()
        .map(|c| encode(c))
        .collect::<Vec<_>>();
    let mut segtree = SegmentTree::new(n);
    for i in 0..n {
        segtree.update(i, s[i]);
    }
    let q = scanner.read::<usize>().unwrap();
    let mut writer = BufWriter::new(stdout());
    for _ in 0..q {
        let line = scanner.read_line().unwrap();
        let params = line.trim().split_whitespace().collect::<Vec<_>>();
        let t = params[0].parse::<usize>().unwrap();
        if t == 1 {
            let i = params[1].parse::<usize>().unwrap() - 1;
            let x = encode(params[2].chars().next().unwrap());
            segtree.update(i, x);
        } else {
            let l = params[1].parse::<usize>().unwrap() - 1;
            let r = params[2].parse::<usize>().unwrap() - 1;
            writeln!(&mut writer, "{}", segtree.query(l, r)).unwrap();
        }
    }
}

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

struct SegmentTree {
    size: usize,
    content: Vec<usize>,
    values: Vec<Vec<usize>>,
}
impl SegmentTree {
    fn new(n: usize) -> SegmentTree {
        let mut size = 1;
        while size < n {
            size *= 2;
        }
        let len = 2 * size - 1;
        SegmentTree {
            size: size,
            content: vec![26; size],
            values: vec![vec![0; 26]; len],
        }
    }
    fn update(&mut self, i: usize, x: usize) {
        if self.content[i] == x {
            return;
        }
        let size = self.size;
        self.update_rec(0, 0, size - 1, i, x);
        self.content[i] = x;
    }
    fn update_rec(&mut self, index: usize, l: usize, r: usize, i: usize, x: usize) {
        if self.content[i] < 26 {
            self.values[index][self.content[i]] -= 1;   
        }
        self.values[index][x] += 1;
        if l == i && r == i {
            return;
        }
        let mid = (l + r) / 2;
        if i <= mid {
            self.update_rec(2 * index + 1, l, mid, i, x);
        } else {
            self.update_rec(2 * index + 2, mid + 1, r, i, x);
        }
    }
    fn query(&self, start: usize, end: usize) -> usize {
        let counts = self.query_rec(0, 0, self.size - 1, start, end);
        counts.into_iter().filter(|val| *val > 0).count()
    }
    fn query_rec(&self, index: usize, l: usize, r: usize, start: usize, end: usize) -> Vec<usize> {
        if l == start && r == end {
            return self.values[index].clone();
        }
        let mid = (l + r) / 2;
        if end <= mid {
            self.query_rec(2 * index + 1, l, mid, start, end)
        } else if start > mid {
            self.query_rec(2 * index + 2, mid + 1, r, start, end)
        } else {
            let mut left = self.query_rec(2 * index + 1, l, mid, start, mid);
            let right = self.query_rec(2 * index + 2, mid + 1, r, mid + 1, end);
            for i in 0..26 {
                left[i] += right[i];
            }
            left
        }
    }
}

#[allow(dead_code)]
struct Scanner<R> {
    reader: BufReader<R>,
    buffer: String,
}
impl<R> Scanner<R>
where
    R: Read,
{
    #[allow(dead_code)]
    fn new(inner: R) -> Scanner<R> {
        let reader = BufReader::new(inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    #[allow(dead_code)]
    fn with_capacity(capacity: usize, inner: R) -> Scanner<R> {
        let reader = BufReader::with_capacity(capacity, inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    #[allow(dead_code)]
    fn read_line(&mut self) -> BoxResult<String> {
        self.reader.read_line(&mut self.buffer)?;
        let cloned = self.buffer.trim().to_string();
        self.buffer.clear();
        Ok(cloned)
    }
    #[allow(dead_code)]
    fn read<T>(&mut self) -> BoxResult<T>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed = self.buffer.trim().parse()?;
        self.buffer.clear();
        Ok(parsed)
    }
    #[allow(dead_code)]
    fn read_two<T, U>(&mut self) -> BoxResult<(T, U)>
    where
        T: FromStr,
        T: Copy,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
        U: FromStr,
        U: Copy,
        U::Err: std::fmt::Debug,
        U::Err: std::error::Error,
        U::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let (a, b) = {
            let params = self.buffer.trim().split_whitespace().collect::<Vec<_>>();
            let a = params[0].parse()?;
            let b = params[1].parse()?;
            (a, b)
        };
        self.buffer.clear();
        Ok((a, b))
    }
    #[allow(dead_code)]
    fn read_three<T>(&mut self) -> BoxResult<(T, T, T)>
    where
        T: FromStr,
        T: Copy,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        let nums = self.read_vector()?;
        Ok((nums[0], nums[1], nums[2]))
    }
    #[allow(dead_code)]
    fn read_vector<T>(&mut self) -> BoxResult<Vec<T>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed_vec = self
            .buffer
            .trim()
            .split_whitespace()
            .map(|s| s.parse())
            .collect::<Result<Vec<_>, _>>()?;
        self.buffer.clear();
        Ok(parsed_vec)
    }
    #[allow(dead_code)]
    fn read_matrix<T>(&mut self, lines: usize) -> BoxResult<Vec<Vec<T>>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        let mut parsed_matrix = vec![];
        for _ in 0..lines {
            self.reader.read_line(&mut self.buffer)?;
            parsed_matrix.push(
                self.buffer
                    .trim()
                    .split_whitespace()
                    .map(|s| s.parse())
                    .collect::<Result<Vec<_>, _>>()?,
            );
            self.buffer.clear();
        }
        Ok(parsed_matrix)
    }
    #[allow(dead_code)]
    fn read_chars(&mut self) -> BoxResult<Vec<char>> {
        self.reader.read_line(&mut self.buffer)?;
        let chars = self.buffer.trim().chars().collect::<Vec<_>>();
        self.buffer.clear();
        Ok(chars)
    }
}


Measured memory_bytes: 272632