unittest
{
	assert( [ "7", "abcdbbd", "6", "2 3 6", "1 5 z", "2 1 1", "1 4 a", "1 7 d", "2 1 7" ].solve == "3\n1\n5" );
}



import core.bitop;
import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto s = input.front.map!( ( a ) => 1L << ( a - 'a' ) ).array;		// 文字をbitに変換
	input.popFront;
	auto q = input.front.to!( long );
	auto qss = new long[ 3 ][ q ];
	foreach( ref qs; qss )
	{
		input.popFront;
		auto as = input.front.split;
		if( as[ 0 ] == "1" ) qs = [ 1L, as[ 1 ].to!( long ) - 1, 1L << ( as[ 2 ][ 0 ] - 'a' ) ];		// 文字をbitに変換
		else                 qs = [ 2L, as[ 1 ].to!( long ) - 1, as[ 2 ].to!( long ) ];
	}
	
	// クエリを処理
	long[] anss;
	auto st = SegmentTree!( long, ( a, b ) => a | b )( s );
	foreach( qs; qss )
	{
		if( qs[ 0 ] == 1 ) st.set( qs[ 1 ], qs[ 2 ] );
		else               anss ~= st.query( qs[ 1 ], qs[ 2 ] ).popcnt;
	}
	return anss.to!( string[] ).join( "\n" );
}

// セグメント木
struct SegmentTree( T, alias op = ( ( a, b ) => a + b ), T I = T.init )
{
	T[] ts;
	
	this( long n )
	{
		ts = new T[ n << 1 ];
		static if( I != T.init ) ts[] = I;
	}
	
	this( T[] qs )
	{
		ts = new T[ qs.length << 1 ];
		ts[ $ >> 1 .. ( $ >> 1 ) + qs.length ] = qs;
		foreach_reverse( i; 1L .. ts.length.signed >> 1 )
		{
			ts[ i ] = op( ts[ i << 1 ], ts[ i << 1 | 1 ] );
		}
	}
	
	void set( long i, T v )
	{
		i += ts.length.signed >> 1;
		ts[ i ] = v;
		for( i >>= 1; 0 < i; i >>= 1 )
		{
			ts[ i ] = op( ts[ i << 1 ], ts[ i << 1 | 1 ] );
		}
	}
	
	auto get( long i )
	{
		i += ts.length.signed >> 1;
		return ts[ i ];
	}
	
	auto query( long l, long r )
	{
		l += ts.length.signed >> 1;
		r += ts.length.signed >> 1;
		auto x = I;
		auto y = I;
		for( ; l < r; l >>= 1, r >>= 1 )
		{
			if( l & 1 )
			{
				x = op( x, ts[ l ] );
				l++;
			}
			if( r & 1 )
			{
				r--;
				y = op( ts[ r ], y );
			}
		}
		return op( x, y );
	}
	
	auto length()
	{
		return ts.length >> 1;
	}
	
	auto toString()
	{
		return format( "ST(%s)", ts[ $ >> 1 .. $ ] );
	}
}
