Last login: Thu Jul  4 14:50:06 on ttys001
jngt@Nagata:Documents$ abc122
zsh: command not found: abc122
jngt@Nagata:Documents$ atcoder
jngt@Nagata:atcoder$ abc122
jngt@Nagata:abc122$ ls
a.py  b.py  c.py
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8[0, 2, 5]
jngt@Nagata:abc122$ 3 7
zsh: command not found: 3
jngt@Nagata:abc122$ 2 3
zsh: command not found: 2
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8
[0, 2, 5]
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 82
0

3
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 82
0
^[  
Traceback (most recent call last):
  File "c.py", line 33, in <module>
    
  File "c.py", line 29, in main
    l, r = MAP()
ValueError: invalid literal for int() with base 10: '8\x1b'
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8
2
0
3
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8> /Users/jngt/Documents/atcoder/abc122/c.py(29)main()
-> for i in range(Q):
(Pdb) 3 7
*** SyntaxError: invalid syntax
(Pdb) 2 3
*** SyntaxError: invalid syntax
(Pdb) t
[0, 1, 1, 2, 2, 2, 3, 3, 0]
(Pdb) q
Traceback (most recent call last):
  File "c.py", line 36, in <module>
    main()
  File "c.py", line 29, in main
    for i in range(Q):
  File "c.py", line 29, in main
    for i in range(Q):
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 67, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8> /Users/jngt/Documents/atcoder/abc122/c.py(29)main()
-> for i in range(Q):
(Pdb) 3 7
*** SyntaxError: invalid syntax
(Pdb) 2 3
*** SyntaxError: invalid syntax
(Pdb) t
[0, 1, 1, 2, 2, 2, 3, 3, 3]
(Pdb) q
Traceback (most recent call last):
  File "c.py", line 36, in <module>
    main()
  File "c.py", line 29, in main
    for i in range(Q):
  File "c.py", line 29, in main
    for i in range(Q):
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 67, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8> /Users/jngt/Documents/atcoder/abc122/c.py(29)main()
-> for i in range(Q):
(Pdb) 3 7
*** SyntaxError: invalid syntax
(Pdb) 2 3
*** SyntaxError: invalid syntax
(Pdb) 1 8
*** SyntaxError: invalid syntax
(Pdb) q
Traceback (most recent call last):
  File "c.py", line 36, in <module>
    main()
  File "c.py", line 29, in main
    for i in range(Q):
  File "c.py", line 29, in main
    for i in range(Q):
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 67, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8> /Users/jngt/Documents/atcoder/abc122/c.py(29)main()
-> for i in range(Q):
(Pdb) 3 7
*** SyntaxError: invalid syntax
(Pdb) 2 3
*** SyntaxError: invalid syntax
(Pdb) 1 8
*** SyntaxError: invalid syntax
(Pdb) q
Traceback (most recent call last):
  File "c.py", line 36, in <module>
    main()
  File "c.py", line 29, in main
    for i in range(Q):
  File "c.py", line 29, in main
    for i in range(Q):
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 67, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8
2
0
3
jngt@Nagata:abc122$ 


### FIXED CODE ###

import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, Q = MAP()
    S = input()
    t = [0] * (N + 1)
    for i in range(N - 1):
        if S[i:i+2] == 'AC':
            t[i + 1] = t[i] + 1
        else:
            t[i + 1] = t[i]
    ans = []
    for i in range(Q):
        l, r = MAP()
        ans.append(t[r - 1] - t[l - 1])
    for i in range(Q):
        print(ans[i])

if __name__ == '__main__':
    main()