###############################################################################



from bisect import bisect_left as binl



def intin():

    input_tuple = input().split()

    if len(input_tuple) <= 1:

        return int(input_tuple[0])

    return list(map(int, input_tuple))





def intina():

    return [int(i) for i in input().split()]





def intinl(count):

    return [intin() for _ in range(count)]





def lcm(x, y):

    while y != 0:

        z = x % y

        x = y

        y = z

    return x





###############################################################################





def main():

    n, q = intin()

    s = eval(input())

    lrlist = intinl(q)

    lrlist = [(l, r) for l, r in lrlist]



    prev = None

    pos_i_list = []

    for i, c in enumerate(s):

        if prev == 'A' and c == 'C':

            pos_i_list.append(i)

        prev = c



    for l, r in lrlist:

        start = binl(pos_i_list, l)

        end = binl(pos_i_list, r)

        print((end - start))





if __name__ == '__main__':

    main()

###############################################################################



from bisect import bisect_left as binl



def intin():

    input_tuple = input().split()

    if len(input_tuple) <= 1:

        return int(input_tuple[0])

    return tuple(map(int, input_tuple))





def intina():

    return [int(i) for i in input().split()]





def intinl(count):

    return [intin() for _ in range(count)]





def modadd(x, y):

    global mod

    return (x + y) % mod





def modmlt(x, y):

    global mod

    return (x * sy) % mod





def lcm(x, y):

    while y != 0:

        z = x % y

        x = y

        y = z

    return x





###############################################################################





def main():

    n, q = intin()

    s = eval(input())

    lrlist = intinl(q)



    prev = None

    pos_i_list = []

    for i, c in enumerate(s):

        if prev == 'A' and c == 'C':

            pos_i_list.append(i)

        prev = c



    for l, r in lrlist:

        start = binl(pos_i_list, l)

        end = binl(pos_i_list, r)

        print((end - start))





if __name__ == '__main__':

    main()

###############################################################################
from bisect import bisect_left as binl


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return list(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


###############################################################################
def main():
    n, q = intin()
    s = eval(input())
    lrlist = intinl(q)
    lrlist = [(l, r) for l, r in lrlist]
    prev = None
    pos_i_list = []
    for i, c in enumerate(s):
        if prev == "A" and c == "C":
            pos_i_list.append(i)
        prev = c
    for l, r in lrlist:
        start = binl(pos_i_list, l)
        end = binl(pos_i_list, r)
        print((end - start))


if __name__ == "__main__":
    main()

###############################################################################
from bisect import bisect_left as binl


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * sy) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


###############################################################################
def main():
    n, q = intin()
    s = eval(input())
    lrlist = intinl(q)
    prev = None
    pos_i_list = []
    for i, c in enumerate(s):
        if prev == "A" and c == "C":
            pos_i_list.append(i)
        prev = c
    for l, r in lrlist:
        start = binl(pos_i_list, l)
        end = binl(pos_i_list, r)
        print((end - start))


if __name__ == "__main__":
    main()

-    return list(map(int, input_tuple)) +    return tuple(map(int, input_tuple)) + + +def modadd(x, y): +    global mod +    return (x + y) % mod + + +def modmlt(x, y): +    global mod +    return (x * sy) % mod -    lrlist = [(l, r) for l, r in lrlist]