function main(arg) {
	arg = arg.split("\n")
	arg.shift()
	var s = arg.shift().split("")
	arg = arg.map(e => e.split(" ").map(Number))
	var result = new Array(arg.length).fill(0)
	for (var i = 0; i < s.length - 1; i++) {
		if (s[i] + s[i + 1] == 'AC') {
			for (var t = 0; t < arg.length; t++) {
				var n = arg[t][0] - 1
				var m = arg[t][1] - 1
				if (n <= i && i <= m - 1) {
					result[t]++
				}
				// console.log(s[i] + s[i + 1] + n + ":" + m)
			}
		}
	}
	result.forEach(e => {
		console.log(e)
	})
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));