input()
s = input()
ac_locates = []

for i, c in enumerate(s):
    if c == "A":
        if s[i+1] == "C":
            ac_locates.append(i+1)

def seach(start, end):
    bs = True
    last = len(ac_locates)
    for i, n in enumerate(ac_locates):
        if bs and n >= start:
            first = i
            bs = False
        if n >= end:
            last = i
            break
    print(first, last)
    return last - first

print(ac_locates)
try:
    while True:
        s, e = map(int, input().split())
        print("case:", s, e)
        print(seach(s, e))
except EOFError:
    pass
