unittest
{
	assert( [ "8 3", "ACACTACG", "3 7", "2 3", "1 8" ].parse.expand.solve == "2\n0\n3" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

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

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nq = input.front.split.to!( long[] );
	input.popFront;
	auto s = input.front;
	auto lrs = new long[][]( nq[ 1 ], 2 );
	foreach( ref lr; lrs )
	{
		input.popFront;
		lr = input.front.split.to!( long[] );
	}
	return tuple( s, lrs );
}

auto solve( string s, long[][] lrs )
{
	// s[ 0 .. i ]の"AC"の数を集計
	auto ts = new long[ s.length + 1 ];
	for( auto i = 1L; i < ts.length; i++ )
	{
		ts[ i ] = ts[ i - 1 ] + ( s[ i - 1 ] == 'A' && s[ i ] == 'C' );
	}
	
	// 集計結果からs[ l - 1 .. r ]の"AC"の数を計算
	auto anss = new long[]( lrs.length );
	foreach( ref ans, lr; lockstep( anss, lrs ) )
	{
		ans = ts[ lr[ 1 ] - 1 ] - ts[ lr[ 0 ] - 1 ];
	}
	
	return anss.to!( string[] ).join( "\n" );
}
