using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		var t=sc.S;
		var sd=new Sd(n+1);
		for(int i = 0;i<n;i++) {
			sd.Add(i+1,1<<(t[i]-'a'));
		}
		int q=sc.I;
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<q;i++) {
			var e=sc.Sa;
			if(e[0]=="1"){
				sd.Add(int.Parse(e[1]),1<<(e[2][0]-'a'));
			}
			else{
				sb.Append(Pc((int)sd.Get(int.Parse(e[1]),int.Parse(e[2])))+"\n");
			}
		}
		Console.Write(sb);
	}
	static int Pc(int n){
		n-=(n>>1)&0x55555555;
		n=(n&0x33333333)+((n>>2)&0x33333333);
		return ((n+(n>>4)&0xF0F0F0F)*0x1010101)>>24;
    }
}
public class Sd{
	public long[] h1,h2;
	public int n,m;
	public Sd(int n){
		this.n=n;
		m=(int)Sqrt(n)+1;
		h1=new long[n];
		h2=new long[m];
	}
	private long Fu(long a,long b){
		return a|b;
	}
	public void Add(int a,int k){
		int g=a/m,ml=g*m,mp=Min(ml+m,n);
		h2[g]=h1[a]=k;
		for(int i = g*m;i<mp;i++) {
			h2[g]=Fu(h2[g],h1[i]);
		}
	}
	public long Get(int l,int r){
		int ml=(l+m-1)/m,mr=(r-m+1)/m,mp=Min(ml*m,r+1);
		long p=h1[l];
		for(int i = l;i<mp;i++) {
			p=Fu(p,h1[i]);
		}
		for(int i = ml;i<=mr;i++) {
			p=Fu(p,h2[i]);
		}
		for(int i = Max(ml*m,mr*m+m);i<=r;i++) {
			p=Fu(p,h1[i]);
		}
		return p;
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 37956