using System;
using System.Collections.Generic;
using static Assistant.Input;
using System.Linq;
using Assistant;
using System.Text;

namespace ABC157E
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt;
            var S = Console.ReadLine();
            var Q = ReadInt;

            BIT[] bits = new BIT[26].Select(a => new BIT(N + 1)).ToArray();
            for (int i = 0; i < N; i++)
            {
                int index = S[i] - 'a';
                bits[index].Add(i + 1, i + 1, 1);
            }
            //for (int i = 0; i < 26; i++)
            //{
            //    Console.Write(i + ":");
            //    bits[i].DrawBIT();
            //}

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < Q; i++)
            {
                var input = Console.ReadLine().Split();
                if (input[0][0] == '1')
                {
                    //change
                    int index = int.Parse(input[1]);
                    int to = input[2][0] - 'a';
                    for (int k = 0; k < 26; k++)
                    {
                        long a = bits[k].Sum(index, index);
                        if (to == k)
                        {
                            if (a != 0) continue;
                            bits[k].Add(index, index, 1);
                        }
                        else if (a > 0)
                        {
                            bits[k].Add(index, index, -1);
                        }
                    }
                }
                else
                {
                    //count
                    int l = int.Parse(input[1]);
                    int r = int.Parse(input[2]);
                    int count = 0;
                    for (int k = 0; k < 26; k++)
                    {
                        if (bits[k].Sum(l, r) > 0) count++;
                    }
                    sb.AppendLine(count.ToString());
                }
                //for (int t = 0; t < 26; t++)
                //{
                //    Console.Write(t + 1 + ":");
                //    bits[t].DrawBIT();
                //}

            }

            Console.Write(sb);
        }


    }

    class BIT
    {
        long[] bit0, bit1;  //1-indexed
        int n;
        public BIT(int n)
        {
            bit0 = new long[n + 1];
            bit1 = new long[n + 1];
            this.n = n;
        }

        public long Sum(int l, int r)
        {
            long ret = 0;
            ret += Sum(bit0, r) + Sum(bit1, r) * r;
            ret -= Sum(bit0, l - 1) + Sum(bit1, l - 1) * (l - 1);
            return ret;
        }

        long Sum(long[] bit, int i)
        {
            long s = 0;
            while (i > 0)
            {
                s += bit[i];
                i -= i & -i;
            }
            return s;
        }

        public void Add(int l, int r, int a)
        {
            Add(bit0, l, -a * (l - 1));
            Add(bit1, l, a);
            Add(bit0, r + 1, a * r);
            Add(bit1, r + 1, -a);
        }

        void Add(long[] bit, int i, int a)
        {
            while (i <= n)
            {
                bit[i] += a;
                i += i & -i;
            }
        }

        public void DrawBIT()
        {
            for (int i = 1; i <= n; i++)
            {
                Console.Write(Sum(i, i) + " ");
            }
            Console.WriteLine();
        }
    }
}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static string ReadString => ReadNext();
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        //drawmap
        //drawarray
    }
}


Measured memory_bytes: 221872