Buggy python submission (verdict: Runtime Error):
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
for j, temp in enumerate(a):
    str_sub = string[temp[0]-1:temp[1]]
    try:
        print(test_dict[str_sub])
    except:
        test_dict[str_sub] = str_sub.count('AC')
        print(test_dict[str_sub])
    #print(test_dict[str_sub])

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Runtime Error):
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
for j, temp in enumerate(a):
    #print(temp)
    str_sub = string[temp[0]-1:temp[1]]
    #print('j',j)
    if j == 0:
        test_dict[str_sub] = str_sub.count('AC')
        result = str(test_dict[str_sub])
        continue
    if test_dict.get(str_sub) and j >= 1:
        #print(test_dict.get(str_sub))
        result += '\n' + str(test_dict.get(str_sub))
        continue
    test_dict[str_sub] = str_sub.count('AC')
    result += '\n' + str(test_dict[str_sub])
    #print(test_dict[str_sub])
    #print('result', result)
print(result)


Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Runtime Error):
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
for j, temp in enumerate(a):
    #print(temp)
    str_sub = string[temp[0]-1:temp[1]]
    if j == 0:
        test_dict[str_sub] = str_sub.count('AC')
        result = str(test_dict[str_sub])
    if test_dict.get(str_sub):
        #print(test_dict.get(str_sub))
        result += '\n' + str(test_dict.get(str_sub))
        continue
    test_dict[str_sub] = str_sub.count('AC')
    result += '\n' + str(test_dict[str_sub])
    #print(test_dict[str_sub])

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Runtime Error):
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    try:
        result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
    except:
        test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
        result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result.lstrip())

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Runtime Error):
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += '\n' + str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result.lstrip())

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Runtime Error):
test_dict = {}
result = ''
for temp in a:
    try:
        result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
    except:
        test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
        result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result.lstrip())

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Runtime Error):
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += '\n' + str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result.lstrip())

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Runtime Error):
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += '\n' + str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result.lstrip)

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Runtime Error):
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += '\n' + str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result)

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Runtime Error):
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += '\n' + str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Runtime Error):
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += str(test_dict[string[temp[0]-1:temp[1]]])

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
for j, temp in enumerate(a):
    #print(temp)
    str_sub = string[temp[0]-1:temp[1]]
    #print('j',j)
    if j == 0:
        test_dict[str_sub] = str_sub.count('AC')
        result = str(test_dict[str_sub])
        continue
    if test_dict.get(str_sub) and j >= 1:
        #print(test_dict.get(str_sub))
        result += '\n' + str(test_dict.get(str_sub))
        continue
    test_dict[str_sub] = str_sub.count('AC')
    result += '\n' + str(test_dict[str_sub])
    #print(test_dict[str_sub])
    #print('result', result)
print(result)

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
for temp in a[:100000]:
    #print(temp)
    str_sub = string[temp[0]-1:temp[1]]
    if test_dict.get(str_sub):
        print(test_dict.get(str_sub))
        continue
    test_dict[str_sub] = str_sub.count('AC')
    print(test_dict[str_sub])

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i,j in enumerate(range(Q)):
    temp = map(int, raw_input().split())
    if i == 0:
        result = str(string[temp[0]-1:temp[1]].count('AC'))
    else:
        result += '\n' + str(string[temp[0]-1:temp[1]].count('AC'))
print(result)

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
for i,temp in enumerate(a):
    if i == 0:
        result = str(string[temp[0]-1:temp[1]].count('AC'))
    else:
        result += '\n' + str(string[temp[0]-1:temp[1]].count('AC'))
print(result)

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
for temp in a:
    print(string[temp[0]-1:temp[1]].count('AC'))

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
for temp in a:
    str_sub = string[temp[0]-1:temp[1]]
    #print(str_sub)
    result = 0
    print(str_sub.count('AC'))

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
for temp in a:
    str_sub = string[temp[0]-1:temp[1]]
    #print(str_sub)
    result = 0
    for i in range(len(str_sub)-1):
        if str_sub[i:i+2] == 'AC':
            result += 1
    print(result)

Fixed submission:
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])