#include <bits/stdc++.h>
using namespace std;

vector < set<int> > adj(28);
string s;
char c;
int q, a, b, d, ans;
int main()
{
 	int n;
    cin >> n >> s >> q;
    s = 'a' + s;
    for(int i = 1; i < s.size(); ++i)
        adj[s[i] - 'a'].insert(i);
    set<int>::iterator it;
    while(q--)
    {
        cin >> a;
        if(a == 1)
        {
            cin >> b >> c;
            adj[s[b] - 'a'].erase(b);
            s[b] = c;
            adj[c - 'a'].insert(b);
        }
        else
        {
            ans = 0;
            cin >> b >> d;
            for(int i = 0; i < 27; ++i)
            {
                it = adj[i].lower_bound(b);
              	
                ans += (*it <= d && *it >= b);
            }
            cout << ans << '\n';
        }
    }
}