using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class SegmentTree<T> {
    public int Size;
    public T[] Node;
    public Func<T, T, T> Calc;
    Func<T, T, bool> Eq;
    T Def;

    public SegmentTree(int n, T[] init, T def, Func<T, T, T> calc, Func<T, T, bool> eq) {
        Calc = calc;
        Def = def;
        Eq = eq;
        Size = 1;
        while(Size < n) Size *= 2;
        Node = new T[2 * Size - 1];
        for(int i = 0; i < init.Length; i++) {
            Node[(Size - 1) + i] = init[i];
        }
        for(int i = init.Length; i < Size; i++) {
            Node[(Size - 1) + i] = Def;
        }
        for(int i = (Size - 1) - 1; 0 <= i; i--) {
            Node[i] = Calc(Node[2 * i + 1], Node[2 * i + 2]);
        }
    }

    public void Update(int index, T value) {
        int pos = (Size - 1) + index;
        if(!Eq(Node[pos], value)) {
            Node[pos] = value;
            while(0 < pos) {
                pos = (pos - 1) / 2;
                Node[pos] = Calc(Node[2 * pos + 1], Node[2 * pos + 2]);
            }
        }
    }

    public T GetRange(int a, int b) {
        return GetRange(a, b, 0, 0, Size);
    }

    public T GetRange(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) {
            return Def;
        }
        if(a <= l && r <= b) {
            return Node[k];
        }
        T vl = GetRange(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = GetRange(a, b, k * 2 + 2, (l + r) / 2, r);
        return Calc(vl, vr);
    }
}
class E {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int N;
        Input(out N);
        string S;
        Input(out S);
        int Q;
        Input(out Q);
        bool[][] init = new bool[N][];
        for(int i = 0; i < N; i++) {
            init[i] = new bool[26];
            init[i][S[i] - 97] = true;
        }
        SegmentTree<bool[]> seg = new SegmentTree<bool[]>(N, init, new bool[26],
            delegate (bool[] a, bool[] b) {
                bool[] ret = new bool[26];
                for(int i = 0; i < 26; i++) {
                    ret[i] = a[i] || b[i];
                }
                return ret;
            },
            delegate (bool[] a, bool[] b) {
                for(int i = 0; i < 26; i++) {
                    if(a[i] != b[i]) {
                        return false;
                    }
                }
                return true;
            }
        );
        for(int i = 0; i < Q; i++) {
            string t, a, b;
            Input(out t, out a, out b);
            if(int.Parse(t) == 1) {
                bool[] ins = new bool[26];
                ins[b[0] - 97] = true;
                seg.Update(int.Parse(a) - 1, ins);
            } else {
                bool[] result = seg.GetRange(int.Parse(a) - 1, int.Parse(b));
                int count = 0;
                for(int j = 0; j < 26; j++) {
                    if(result[j] == true) {
                        count++;
                    }
                }
                Print(count);
            }
        }
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 103160