#include <bits/stdc++.h>
using namespace std;
struct A {
  int x;
  char y;
  int s;
  int e;
  bool operator<(A o) const {
    if (x != o.x)
      return x < o.x;
    else
      return y < o.y;
  }
};
struct B {
  int x, y, t;
};
struct C {
  int x;
  char y;
};
vector<A> v;
vector<B> Quary;
bool check[26];
bool c[500001];
stack<C> st;
string s;
void merge(int x, char y) {
  st.push({x, s[x]});
  s[x] = y;
}
void split(C x) { s[x.x] = x.y; }
void solve(int ss, int e, vector<A> Edge) {
  int si = Quary[ss].t, se = Quary[e].t;
  vector<A> left;
  vector<A> right;
  int time = st.size();
  int mid = (ss + e) / 2;
  int tmp = Quary[mid].t;
  for (int i = 0; i < Edge.size(); i++) {
    if (Edge[i].s <= si && se <= Edge[i].e) {
      merge(Edge[i].x, Edge[i].y);
      continue;
    }
    if (Edge[i].s <= tmp) left.push_back(Edge[i]);
    if (Edge[i].e >= tmp) right.push_back(Edge[i]);
  }
  if (ss == e) {
    memset(check, false, sizeof(check));
    for (int i = Quary[ss].x - 1; i < Quary[ss].y; i++) {
      check[(s[i] - 'a')] = true;
    }
    int ans = 0;
    for (int i = 0; i <= 25; i++) {
      if (check[i]) ans += 1;
    }
    cout << ans << '\n';
  } else {
    solve(ss, mid, left);
    solve(mid + 1, e, right);
  }
  while (st.size() > time) {
    split(st.top());
    st.pop();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  cin >> s;
  int m;
  cin >> m;
  set<A> ss;
  for (int i = 0; i < m; i++) {
    int x, z;
    char y;
    cin >> z;
    if (z == 1) {
      cin >> x >> y;
      if (!c[x]) {
        c[x] = true;
        ss.insert({x, y, i});
      } else {
        A p = *ss.find({x});
        p.e = i;
        ss.erase(p);
        v.push_back(p);
        ss.insert({x, y, i});
      }
    } else {
      int nx, ny;
      cin >> nx >> ny;
      Quary.push_back({nx, ny, i});
    }
  }
  while (!ss.empty()) {
    A p = *ss.begin();
    ss.erase(p);
    p.e = m + 1;
    v.push_back(p);
  }
  if (Quary.size() > 0) solve(0, Quary.size() - 1, v);
}
