void main()
{
    long n = rdElem;
    dchar[] s = rdDchar;

    Fenwick[] tree = new Fenwick[26];
    foreach (i; 0 .. 26) tree[i] = Fenwick(n);
    foreach (i, x; s)
    {
        tree[x-'a'].add(i+1, 1);
    }

    long q = rdElem;
    foreach (i; 0 .. q)
    {
        long num, pos;
        string c;
        rdVals(num, pos, c);

        if (num == 1)
        {
            dchar d = c.to!dchar;
            if (d == s[pos-1]) continue;
            tree[s[pos-1]-'a'].add(pos, -1);
            tree[d-'a'].add(pos, 1);
            s[pos-1] = d;
        }
        else
        {
            long end = c.to!long;
            long cnt;
            foreach (j; 0 .. 26)
            {
                if (tree[j].sum(end) - tree[j].sum(pos-1)) ++cnt;
            }
            cnt.writeln;
        }
    }
}

struct Fenwick
{
    long[] tree;

    this(long n)
    {
        tree.length = n + 1;
    }

    void add(long idx, long val)
    {
        for (long i = idx; i < tree.length; i += i & -i)
        {
            tree[i] += val;
        }
    }

    long sum(long idx)
    {
        long result;
        for (long i = idx; i > 0; i -= i & -i)
        {
            result += tree[i];
        }
        return result;
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;