using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        private static long mod = 1000000007;

        static void Main(string[] args)
        {
            var r1 = ReadSplit();
            var n = r1[0].Int();
            var q = r1[1].Int();
            var s = Read();
            var l = new int[n];
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'C' && i - 1 >= 0)
                {
                    if (s[i - 1] == 'A')
                    {
                        l[i] = l[i - 1] + 1;
                    }
                    else
                    {
                        l[i] = l[i - 1];
                    }
                }
                else
                {
                    if (i - 1 >= 0)
                    {
                        l[i] = l[i - 1];
                    }
                }
            }
            var ansList = new List<int>();
            for (int i = 0; i < q; i++)
            {
                var r2 = ReadSplit();
                var st = r2[0].Int();
                var e = r2[1].Int();
                var ans = 0;
                if (st - 2 < 0)
                {
                    ans = l[e - 1];
                }
                else
                {
                    ans = l[e - 1] - l[st - 2];
                }
                if (s[st - 1] == 'C' && st - 2 >= 0)
                {
                    if (s[st - 2] == 'A')
                    {
                        ans--;
                    }
                }
                ansList.Add(ans);
            }
            foreach (var item in ansList)
            {
                Write(item);
            }
            Read();
        }
        
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 19520