def input_data():
    s = input()
    n, _ = (int(d_s) for d_s in (input() + ' 0').split())
    t = [[int(d) for d in (input() + ' 0').split()][:-1] for _ in range(n)]
    return s, t


def do_task(s, t):
    for line in t:
        str_work = s[line[0]:line[1]]
        if len(str_work)==0:
            print(0)
        else:
            words(str_work)


def words(s):
    res = 1
    iter_s = iter(s)
    next(iter_s)
    list_res = [ord(n) - ord(m) for n, m in zip(s, iter_s)]
    for r in list_res:
        if r > 0:
            res += 1
    print(res)




def my_code():
    s, t = input_data()
    do_task(s, t)
    pass


if __name__ == '__main__':
    my_code()
