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