module S = Set.Make (struct type t = int let compare = compare end);;
let () =
    let main () =
        let n = read_line () |> int_of_string in
        let s = read_line () in
        let letter = Array.make 26 S.empty in
        for i = 0 to n - 1 do
            let code = int_of_char s.[i] - 97 in
            letter.(code) <- S.add (i + 1) letter.(code)
        done;
        let q = read_line () |> int_of_string in
        for i = 1 to q do
            Scanf.sscanf (read_line ()) "%d %d %s" (fun command a b ->
                if command = 1 then (
                    let c = int_of_char s.[a - 1] - 97 in
                    letter.(c) <- S.remove a letter.(c);
                    let c = int_of_char b.[0] - 97 in
                    letter.(c) <- S.add a letter.(c)
                ) else (
                    let r = int_of_string b in
                    let rec loop i acc =
                        if i = 26 then acc else
                            let _,_,s = S.split (a - 1) letter.(i) in
                            let s,_,_ = S.split (r + 1) s in
                            let acc = if S.is_empty s then acc else acc + 1 in
                            loop (i + 1) acc
                    in
                    loop 0 0 |> Printf.printf "%d\n"
                )
            )
        done
    in
    main ()