/*
 _____ ____ _____   ___   ___   ___   ___ 
|_   _/ __ \_   _| |__ \ / _ \ |__ \ / _ \
  | || |  | || |      ) | | | |   ) | | | |
  | || |  | || |     / /| | | |  / /| | | |
 _| || |__| || |_   / /_| |_| | / /_| |_| |
|_____\____/_____| |____|\___/ |____|\___/ 
*/
#include <bits/stdc++.h>
#include <fstream>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
// pair<int,int>ert(x==y); gives run time when false
using namespace std;
int n, t;
string x;
vector<vi> v;
vi f(int a, int b, int m, int l, int r)
{
    if (l > b || r < a)
        return {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    if (l >= a && r <= b)
    {
        return v[m];
    }
    int mid = (l + r) / 2;
    vi t1 = f(a, b, 2 * m, l, mid);
    vi t2 = f(a, b, 2 * m + 1, mid + 1, r);

    vi temp = t1;
    rep(i, 0, 26)
    {
        temp[i] += t2[i];
    }
    return temp;
}
void upd(int i, char g)
{
    char temp = x[i - t];
    x[i - t] = g;
    while (i > 0)
    {
        v[i][temp-'a']--;
        v[i][g-'a']++;
        i /= 2;
    }
}
int main()
{
    CIN;
    cin >> n >> x;
    t = pow(2, ceil((double)log2(n)));
    v.resize(2 * t);
    rep(i, t, t + n)
    {
        vi temp(26, 0);
        temp[x[i - t] - 'a']++;
        v[i] = temp;
    }
    rep(i,t+n,2*t){
        vi temp(26, 0);
        v[i] = temp;
    }
    per(i, t - 1, 0)
    {
        v[i] = v[2 * i];
        rep(j, 0, 26)
        {
            v[i][j] += v[2 * i + 1][j];
        }
    }
    int q;
    cin >> q;
    while (q--)
    {
        int n1;
        cin >> n1;
        n1--;
        if (!n1)
        {
            int n2;
            char g;
            cin >> n2 >> g;
            upd(n2 + t - 1, g);
        }
        else
        {
            int l, r;
            cin >> l >> r;
            vi ms = f(l, r, 1, 1, t);
            int sum = 0;
            for (int i = 0; i <= 26; i++)
            {
                if (ms[i])
                    sum++;
            }
            cout << sum-1 << '\n';
        }
    }
}

Measured memory_bytes: 140060