Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.

You've got string s = s_1s_2... s_{n} (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers l_{i}, r_{i} (1 ≤ l_{i} < r_{i} ≤ n). The answer to the query l_{i}, r_{i} is the number of such integers i (l_{i} ≤ i < r_{i}), that s_{i} = s_{i} + 1.

Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.


-----Input-----

The first line contains string s of length n (2 ≤ n ≤ 10^5). It is guaranteed that the given string only consists of characters "." and "#".

The next line contains integer m (1 ≤ m ≤ 10^5) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers l_{i}, r_{i} (1 ≤ l_{i} < r_{i} ≤ n).


-----Output-----

Print m integers — the answers to the queries in the order in which they are given in the input.


-----Examples-----
Input
......
4
3 4
2 3
1 6
2 6

Output
1
1
5
4

Input
#..###
5
1 3
5 6
1 5
3 6
3 4

Output
1
1
2
2
0

Source: codeforces | Difficulty: EASY
Tags: Dynamic programming

Implementation


Solutions:
l = len
import sys
c = sys.stdin.readline()
d = [0] * l(c)
p = c[0]
for (i, t) in enumerate(c[1:]):
	d[i + 1] = d[i] + 1 * (t == p)
	p = t
for _ in range(int(sys.stdin.readline())):
	(l, r) = map(int, sys.stdin.readline().split())
	sys.stdout.write(str(d[r - 1] - d[l - 1]) + '\n')


s = input()
n = int(input())
arr = [0] * len(s)
res = ''
for i in range(1, len(s)):
	arr[i] = arr[i - 1] + (s[i] == s[i - 1])
for i in range(n):
	(l, r) = map(int, input().split())
	res += str(arr[r - 1] - arr[l - 1]) + '\n'
print(res)


st = ''
s = input()
n = len(s)
l = [0]
for i in range(0, n - 1):
	if s[i] == s[i + 1]:
		l.append(1)
	else:
		l.append(0)
q = int(input())
for i in range(1, n):
	l[i] += l[i - 1]
for _ in range(q):
	(low, r) = map(int, input().split())
	st += str(l[r - 1] - l[low - 1]) + '\n'
print(st)


s = input()
m = int(input())
lst = [0]
for i in range(len(s) - 1):
	if s[i + 1] == s[i]:
		lst.append(1)
	else:
		lst.append(0)
s1 = []
sex = 0
for i in range(len(lst)):
	sex += lst[i]
	s1.append(sex)
for i in range(m):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	print(s1[y] - s1[x])


entrada = input()
iguais = []
x = 0
for s in range(len(entrada) - 1):
	iguais.append(x)
	if entrada[s] == entrada[s + 1]:
		x += 1
iguais.append(x)
queries = int(input())
final = []
for q in range(queries):
	res = 0
	(a, b) = map(int, input().split())
	res = iguais[b - 1] - iguais[a - 1]
	final.append(res)
for r in final:
	print(r)


from sys import stdin
s = stdin.readline()
n = len(s)
arr = [0] * (n + 1)
for i in range(n - 1):
	arr[i + 1] = arr[i]
	if s[i] == s[i + 1]:
		arr[i + 1] += 1
for _ in range(int(stdin.readline())):
	(l, r) = [int(x) for x in stdin.readline().split()]
	print(arr[r - 1] - arr[l - 1])


import math, sys

def opt(s, l, r):
	if l < r:
		if s[l] == s[l + 1]:
			return 1 + opt(s, l + 1, r)
		else:
			return opt(s, l + 1, r)
	else:
		return 0
s = str(input())
z = 0
w = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		z += 1
	w.append(z)
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(w[b - 1] - w[a - 1])


s = input()
l = len(s)
b = [0] * l
for i in range(l - 1):
	b[i + 1] = b[i] + (s[i] == s[i + 1])
a = []
for t in range(int(input())):
	(l, r) = map(int, input().split())
	cnt = b[r - 1] - b[l - 1]
	a.append(cnt)
print(*a)


s = input()
n = int(input())
ss = [0]
o = []
mx = 0
for x in range(0, len(s) - 1):
	if s[x] == s[x + 1]:
		mx += 1
	ss.append(mx)
for x in range(n):
	i = list(map(int, input().split()))
	o.append(ss[i[1] - 1] - ss[i[0] - 1])
for b in o:
	print(b)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
l = z()
p = [0] + [0]
for i in range(len(l) - 1):
	if l[i] == l[i + 1]:
		p.append(1 + p[-1])
	else:
		p.append(p[-1])
ans = []
for _ in range(int(z())):
	(l, r) = zz()
	ans.append(p[r] - p[l])
print('\n'.join((str(i) for i in ans)))


npt = input()
num = int(input())
x = [0] * 1000 * 1000
x = list(x)
i = 1
while i != len(npt):
	if npt[i] == npt[i - 1]:
		x[i] = x[i - 1] + 1
	else:
		x[i] = x[i - 1]
	i += 1
for i in range(num):
	(npt2, npt3) = input().split()
	npt2 = int(npt2)
	npt3 = int(npt3)
	xx = x[npt3 - 1] - x[npt2 - 1]
	print(xx)


from sys import stdin
s = input()
n = len(s)
cnt = [0] * (n + 1)
for i in range(n - 1):
	if s[i] == s[i + 1]:
		cnt[i + 1] += 1
for i in range(1, n + 1):
	cnt[i] += cnt[i - 1]
m = int(input())
for i in range(m):
	(l, r) = map(int, stdin.readline().split())
	print(cnt[r - 1] - cnt[l - 1])


import sys
from math import sqrt
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
str = input()
n = len(str)
m = int(input())
dp = [0] * (n + 1)
for i in range(1, n):
	if str[i - 1] == str[i]:
		dp[i + 1] = dp[i] + 1
	else:
		dp[i + 1] = dp[i]
for i in range(m):
	(l, r) = map(int, input().split())
	print(dp[r] - dp[l])


from sys import stdin, stdout
s = stdin.readline()
n = len(s)
c = [0] * n
ans = []
for i in range(n):
	if i + 1 < n and s[i] == s[i + 1]:
		c[i] = 1
p = [0] * n
for i in range(1, n):
	p[i] = p[i - 1] + c[i - 1]
for i in range(int(stdin.readline())):
	(l, r) = map(int, stdin.readline().split())
	ans.append(str(p[r - 1] - p[l - 1]))
stdout.write('\n'.join(ans))


string = input()
array = [0 for i in range(len(string))]
for i in range(1, len(string)):
	array[i] = array[i - 1]
	if string[i] == string[i - 1]:
		array[i] += 1
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	a -= 1
	b -= 1
	print(array[b] - array[a])


s = input()
r = int(input())
t = []
m = [0] * len(s)
for b in range(r):
	t.append(tuple((int(x) for x in input().split())))
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		m[i + 1] = m[i] + 1
	else:
		m[i + 1] = m[i]
for x in range(r):
	print(m[t[x][1] - 1] - m[t[x][0] - 1])


s = list(input())
q = int(input())
result = [0] * len(s)
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		result[i + 1] = result[i] + 1
	else:
		result[i + 1] = int(result[i])
for _ in range(q):
	(l, r) = map(int, input().split())
	print(result[r - 1] - result[l - 1])


import sys
input = sys.stdin.readline
s = input()
ps = [0]
n = len(s)
for i in range(0, n - 1):
	if s[i] == s[i + 1]:
		ps.append(1 + ps[-1])
	else:
		ps.append(ps[-1])
m = int(input())
while m:
	(l, r) = map(int, input().split())
	print(ps[r - 1] - ps[l - 1])
	m -= 1


s = input()
n = int(input())
a = [0]
for i in range(len(s) - 1):
	a += [a[-1] + (s[i] == s[i + 1])]
d = ''
for i in range(n):
	(l, r) = map(int, input().split())
	d += str(a[r - 1] - a[l - 1]) + '\n'
print(d)


s = input()
m = int(input())
a = []
for i in range(m):
	temp = input().strip().split()
	a.append([int(temp[0]) - 1, int(temp[1]) - 1])
dp = [0 for i in range(len(s))]
for i in range(1, len(s)):
	dp[i] = dp[i - 1] + int(s[i - 1] == s[i])
for item in a:
	print(dp[item[1]] - dp[item[0]])


s = input()
m = int(input())
q = [[int(j) for j in input().split()] for z in range(m)]
count = [0] * len(s)
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		count[i + 1] = count[i] + 1
	else:
		count[i + 1] = count[i]
for i in range(m):
	print(count[q[i][1] - 1] - count[q[i][0] - 1])


a = input()
t = len(a)
dp = [1] * t
for i in range(1, t):
	if a[i - 1] == a[i]:
		dp[i] += dp[i - 1]
	else:
		dp[i] = dp[i - 1]
ans = []
for i in range(int(input())):
	(c, d) = map(lambda x: int(x) - 1, input().split())
	ans.append(str(dp[d] - dp[c]))
print('\n'.join(ans))


n = input()
l = [0] * len(n)
k = 0
for j in range(0, len(n) - 1):
	if n[j] == n[j + 1]:
		k = k + 1
	l[j + 1] = k
for i in range(int(input())):
	(m, r) = map(int, input().split())
	print(l[r - 1] - l[m - 1])


from sys import *
input = stdin.readline
s = input()
m = len(s)
n = int(input())
d = [0]
c = 0
for i in range(1, m):
	if s[i] == s[i - 1]:
		c = c + 1
	d.append(c)
for i in range(n):
	(x, y) = map(int, input().split())
	print(d[y - 1] - d[x - 1])


s = input()
x = [0] * len(s)
for i in range(1, len(s)):
	x[i] = x[i - 1]
	if s[i - 1] == s[i]:
		x[i] += 1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(x[b - 1] - x[a - 1])


s = input()
a = [0]
count = 0
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		count += 1
	a.append(count)
c = ''
for i in range(int(input())):
	(x, y) = map(int, input().split())
	c += str(a[y - 1] - a[x - 1]) + '\n'
print(c)


a = str(input())
b = [0] * len(a)
if '.' not in a or '#' not in a:
	for _ in range(int(input())):
		(l, r) = [int(x) for x in input().split()]
		n = r - l
		print(n)
else:
	for i in range(1, len(a)):
		if a[i] == a[i - 1]:
			b[i] = b[i - 1] + 1
		else:
			b[i] = b[i - 1]
	for _ in range(int(input())):
		(l, r) = [int(x) for x in input().split()]
		n = b[r - 1] - b[l - 1]
		print(n)


s = input()
n = len(s)
rep = [0] * n
for i in range(1, n):
	if s[i - 1] == s[i]:
		rep[i] = rep[i - 1] + 1
	else:
		rep[i] = rep[i - 1]
res = ''
q = int(input())
for _ in range(q):
	(low, high) = [int(i) for i in input().split()]
	res += str(rep[high - 1] - rep[low - 1]) + '\n'
print(res)


s = list(input())
n = int(input())
l = []
sdp = [0] * len(s)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		sdp[i] = 1 + sdp[i - 1]
	else:
		sdp[i] = sdp[i - 1]
for i in range(n):
	l.append([int(_) - 1 for _ in input().split()])
for pair in l:
	print(sdp[pair[1]] - sdp[pair[0]])


s = ''
a = [0]
for i in input():
	a.append(a[-1] + (1 if s == i else 0))
	s = i
for i in range(int(input())):
	(l, r) = map(int, input().split())
	print(a[r] - a[l])


import math
import re
from fractions import Fraction
from collections import Counter

class Task:
	s = ''
	queries = []
	answer = []

	def __init__(self):
		self.s = input()
		self.queries = [[] for _ in range(int(input()))]
		for i in range(len(self.queries)):
			self.queries[i] = [int(x) for x in input().split()]

	def solve(self):
		(s, queries) = (self.s, self.queries)
		d = [0] * len(s)
		d[0] = 1 if s[0] == s[1] else 0
		for i in range(1, len(d) - 1):
			d[i] = d[i - 1] + (s[i + 1] == s[i])
		d[-1] = d[-2]
		for current in queries:
			localAnswer = d[current[1] - 2]
			localAnswer -= d[current[0] - 2] if current[0] >= 2 else 0
			self.answer += [localAnswer]

	def printAnswer(self):
		for x in self.answer:
			print(x)
task = Task()
task.solve()
task.printAnswer()


st = input()
ls = []
for i in range(int(input())):
	ps = tuple(map(int, input().split()))
	ls.append(ps)
arr = [0] * len(st)
for i in range(len(st) - 1):
	if st[i] == st[i + 1]:
		arr[i + 1] = arr[i] + 1
	else:
		arr[i + 1] = arr[i]
for i in range(len(ls)):
	(a, b) = ls[i]
	print(arr[b - 1] - arr[a - 1])


import sys
input = sys.stdin.readline
ins = lambda : input()
ini = lambda : int(input())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
s = ins()
n = len(s)
a = [0] * n
m = ini()
for i in range(1, n):
	a[i] = a[i - 1] + (1 if s[i] == s[i - 1] else 0)
for _ in range(m):
	(l, r) = inm()
	ans = a[r - 1] - a[l - 1]
	print(ans)


from sys import stdin, stdout
s = stdin.readline()[:-1]
n = len(s)
arr = []
q = 0
for i in range(n - 1):
	if s[i] == s[i + 1]:
		q += 1
	arr.append(q)
m = int(input())
for i in range(m):
	(a, b) = map(int, stdin.readline().split())
	if a - 2 == -1:
		stdout.write(str(arr[b - 2]) + '\n')
	else:
		stdout.write(str(arr[b - 2] - arr[a - 2]) + '\n')


s = input()
m = int(input())
dp = [0] * len(s)
for i in range(1, len(s)):
	dp[i] = dp[i - 1] + (s[i] == s[i - 1])
res = []
while m > 0:
	(a, b) = map(int, input().split(' '))
	res.append(str(dp[b - 1] - dp[a - 1]))
	m -= 1
print('\n'.join(res))


from sys import stdin, stdout

class QueryCalculator:

	def __init__(self, database):
		self.smart_coincidences = QueryCalculator.build_smart_coincidences(database)

	def build_smart_coincidences(database):
		smart_coincidences = []
		for i in range(len(database) - 1):
			first_char = database[i]
			next_char = database[i + 1]
			weight = 0
			if first_char == next_char:
				weight = 1
			previous_weight = 0
			if len(smart_coincidences) != 0:
				previous_weight = smart_coincidences[-1]
			smart_coincidences.append(previous_weight + weight)
		return smart_coincidences

	def get_weight(self, query):
		left_weight = 0
		if query.left - 1 >= 0:
			left_weight = self.smart_coincidences[query.left - 1]
		right_weight = self.smart_coincidences[query.right - 1]
		return right_weight - left_weight

class Query:

	def __init__(self, left, right):
		self.left = left - 1
		self.right = right - 1

def smart_solve(database, queries_count, queries):
	result = []
	calculator = QueryCalculator(database)
	for i in range(queries_count):
		query = queries[i]
		weight = calculator.get_weight(query)
		result.append(weight)
	return result
database = stdin.readline().rstrip('\r\n')
queries_count = int(stdin.readline())
queries = []
for i in range(queries_count):
	lst = [int(x) for x in stdin.readline().rstrip('\r\n').split()]
	query = Query(lst[0], lst[1])
	queries.append(query)
lst = smart_solve(database, queries_count, queries)
for result in lst:
	stdout.write(str(result))
	stdout.write('\n')


s = input()
m = int(input())
count = 0
b = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		count += 1
		b.append(count)
	else:
		b.append(count)
for _ in range(m):
	(l, r) = map(int, input().split())
	print(b[r - 1] - b[l - 1])


import sys
input = sys.stdin.readline
string = input().strip()
(psa, last) = ([0], string[0])
for i in range(1, len(string)):
	if string[i] == last:
		psa.append(psa[-1] + 1)
	else:
		psa.append(psa[-1])
	last = string[i]
for i in range(int(input())):
	(l, r) = map(int, input().split())
	print(psa[r - 1] - psa[l - 1])


string = input()
n = int(input())
(a, b) = ([0 for i in range(n)], [0 for i in range(n)])
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
dp = [0] * len(string)
for i in range(len(string) - 1):
	if string[i] == string[i + 1]:
		dp[i + 1] = dp[i] + 1
	else:
		dp[i + 1] = dp[i]
for i in range(n):
	print(dp[b[i] - 1] - dp[a[i] - 1])


s = input()
a = [0]
q = ''
for i in range(1, len(s)):
	a.append(a[i - 1] + (s[i - 1] == s[i]))
for _ in ' ' * int(input()):
	(l, r) = map(int, input().split())
	q += str(a[r - 1] - a[l - 1]) + '\n'
print(q)


s = input()
n = len(s)
dp = [0] * n
prev = s[0]
for i in range(1, n):
	if s[i] == s[i - 1]:
		dp[i] += dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
m = int(input())
for _ in range(m):
	(l, r) = map(int, input().split())
	print(dp[r - 1] - dp[l - 1])


s = str(input())
m = int(input())
p = [0]
for i in range(1, len(s)):
	if s[i - 1] == s[i]:
		p.append(p[i - 1] + 1)
	else:
		p.append(p[i - 1])
for i in range(m):
	(a, b) = map(int, input().split())
	print(p[b - 1] - p[a - 1])


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
s = input()
m = int(input())
q = []
for i in range(m):
	(l, r) = map(int, input().split())
	q.append((l - 1, r - 1))
pre = [0] * len(s)
acc = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		acc += 1
	pre[i] = acc
pre[-1] = pre[-2]
for x in q:
	l = x[0]
	r = x[1]
	print(pre[r - 1] - pre[l] + (1 if s[l] == s[l + 1] else 0))


s = input()
m = int(input())
k = 0
arr = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		k += 1
	arr.append(k)
while m:
	(l, r) = [int(i) for i in input().split()]
	r -= 1
	l -= 1
	m -= 1
	print(arr[r] - arr[l])


s = input()
n = int(input())
s_f = [0] * len(s)
for i in range(len(s) - 1):
	s_f[i + 1] = s_f[i] + (s[i] == s[i + 1])
s = ''
for _ in range(n):
	(l, r) = map(int, input().split())
	s += str(s_f[r - 1] - s_f[l - 1]) + '\n'
print(s)


s = input()
k = [0] * 100000
answer = []
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		k[i] = k[i - 1] + 1
	else:
		k[i] = k[i - 1]
n = int(input())
for j in range(n):
	(x, y) = [int(x) for x in input().split()]
	answer.append(str(k[y - 1] - k[x - 1]))
print('\n'.join(answer))


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
s = input().strip()
l = list(s)
x = [0]
for i in range(1, len(l)):
	if l[i] == l[i - 1]:
		x.append(x[-1] + 1)
	else:
		x.append(x[-1])
q = I()
for i in range(q):
	(l, r) = M()
	print(x[r - 1] - x[l - 1])


from sys import stdin, stdout

def run():
	write = stdout.write
	cadena = stdin.readline()
	values = [0] * len(cadena)
	point = num = 0
	for i in range(1, len(cadena)):
		if cadena[i] == cadena[i - 1]:
			values[i] = values[i - 1] + 1
		else:
			values[i] = values[i - 1]
	n = int(stdin.readline())
	ans = []
	for i in range(n):
		(l, r) = map(int, stdin.readline().split())
		ans.append(str(abs(values[l - 1] - values[r - 1])))
	write('\n'.join(ans))
run()


import sys
import math
st = sys.stdin.readline()
length = len(st) - 1
an = [0] * length
v = st[0]
for i in range(1, length):
	k = 0
	if v == st[i]:
		k = 1
	v = st[i]
	an[i] = an[i - 1] + k
c = int(sys.stdin.readline())
for i in range(c):
	(li, ri) = [int(x) for x in sys.stdin.readline().split()]
	print(an[ri - 1] - an[li - 1])


text = input()
n = len(text)
m = int(input())
queries = [list((int(i) - 1 for i in input().split())) for j in range(m)]
same = [0] * n
for i in range(1, n):
	if text[i] == text[i - 1]:
		same[i] = same[i - 1] + 1
	else:
		same[i] = same[i - 1]
for query in queries:
	print(same[query[1]] - same[query[0]])


s = str(input())
m = int(input())
query = []
cek = [0] * len(s)
for i in range(1, len(s)):
	cek[i] = cek[i - 1]
	if s[i] == s[i - 1]:
		cek[i] += 1
for i in range(m):
	query += [input().split()]
for i in range(m):
	print(cek[int(query[i][1]) - 1] - cek[int(query[i][0]) - 1])


s = input()
ans = [0]
count = 0
for i in range(0, len(s) - 1):
	if s[i] == s[i + 1]:
		count += 1
	ans.append(count)
n = int(input())
while n > 0:
	n -= 1
	(l, r) = tuple(map(int, input().split()))
	print(ans[r - 1] - ans[l - 1])


s = input()
t = int(input())
calc = [0] * len(s)
for (i, _) in enumerate(s):
	if i == 0:
		continue
	if s[i] == s[i - 1]:
		calc[i] = 1 + calc[i - 1]
	else:
		calc[i] = calc[i - 1]
for _ in range(t):
	(l, r) = [int(t) for t in input().split()]
	print(calc[r - 1] - calc[l - 1])


a = input()
n = len(a)
(l, ans) = ([0] * n, [0] * n)
for i in range(1, n):
	l[i] = a[i] == a[i - 1]
	ans[i] = ans[i - 1] + l[i]
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(ans[b - 1] - ans[a - 1])


import math
import bisect
import sys
from collections import OrderedDict
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
S = insr()
cum = []
prev = 0
for i in range(len(S) - 1):
	if S[i] == S[i + 1]:
		cum.append(prev + 1)
		prev += 1
	else:
		cum.append(prev)
cum.append(prev)
M = inp()
for m in range(M):
	(l, r) = invr()
	l -= 1
	r -= 1
	if l > 0:
		print(cum[r - 1] - cum[l - 1])
	else:
		print(cum[r - 1] - 0)


s = input()
m = int(input())
dp = [0] * len(s)
queries = list((map(int, input().split()) for _ in range(m)))
for j in range(len(s) - 1):
	if s[j] == s[j + 1]:
		dp[j] = 1
sumArray = [0] * len(s)
sumArray[1] = dp[0]
for k in range(2, len(s)):
	sumArray[k] = sumArray[k - 1] + dp[k - 1]
for (l, r) in queries:
	print(sumArray[r - 1] - sumArray[l - 1])


s = input().strip()
ll = [0] * 100002
n = int(input().strip())
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		ll[i + 1] = ll[i] + 1
	else:
		ll[i + 1] = ll[i]
j = []
for i in range(n):
	l = list(map(int, input().split()))
	j.append(str(ll[l[-1] - 1] - ll[l[0] - 1]))
print('\n'.join(j))


s = input()
a = [0] * (len(s) + 1)
for i in range(1, len(s)):
	a[i] = a[i - 1]
	if s[i] == s[i - 1]:
		a[i] += 1
n = int(input())
output = []
for i in range(n):
	(l, r) = input().split()
	output.append(a[int(r) - 1] - a[int(l) - 1])
print('\n'.join(map(str, output)))


s = input()
n = int(input())
(a, b) = ([0 for i in range(n)], [0 for i in range(n)])
for i in range(0, n):
	(a[i], b[i]) = map(int, input().split())
count = [0 for i in range(len(s))]
count[0] = 0
for i in range(1, len(s)):
	count[i] = count[i - 1]
	if s[i - 1] == s[i]:
		count[i] += 1
for i in range(0, n):
	print(count[b[i] - 1] - count[a[i] - 1])


x = input()
n = int(input())
arr = [0] * n * 2
for i in range(0, n * 2, 2):
	(arr[i], arr[i + 1]) = [int(x) for x in input().split()]
sum = [0] * len(x)
sum[1] = 1 if x[0] == x[1] else 0
for i in range(1, len(x) - 1):
	if x[i] == x[i + 1]:
		sum[i + 1] = sum[i] + 1
	else:
		sum[i + 1] = sum[i]
for i in range(0, n * 2, 2):
	print(sum[arr[i + 1] - 1] - sum[arr[i] - 1])


import sys
l = sys.stdin.readline().strip()
ls = len(l)
c = input()
c = int(c)
r = []
d = []
k = 0
d.append(0)
for i in range(0, ls - 1):
	if l[i] == l[i + 1]:
		k = k + 1
	d.append(k)
for i in range(0, c):
	(n, m) = sys.stdin.readline().strip().split(' ')
	(n, m) = (int(n) - 1, int(m) - 1)
	r.append(d[m] - d[n])
for s in r:
	print(s)


from sys import stdin, stdout
input = stdin.readline

def Main(s):
	l = len(s)
	dp = [0] * l
	for i in range(1, l):
		if s[i - 1] == s[i]:
			dp[i] = dp[i - 1] + 1
		else:
			dp[i] = dp[i - 1]
	n = int(input())
	for _ in range(n):
		(l, r) = map(int, input().split())
		print(dp[r - 1] - dp[l - 1])
s = input()
Main(s)


S = input()
n = len(S)
Counts = [0] * n
count = 0
ans = ''
old_char = S[0]
for i in range(1, n):
	new_char = S[i]
	if new_char == old_char:
		count += 1
	else:
		old_char = new_char
	Counts[i] = count
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	ans += str(Counts[r - 1] - Counts[l - 1]) + '\n'
print(ans)


s = input()
n = int(input())
l = len(s)
a = [0] * l
for i in range(1, l - 1):
	a[i] = a[i - 1] + int(s[i - 1] == s[i])
a[l - 1] = a[l - 2] + int(s[l - 2] == s[l - 1])
ans = ''
for i in range(n):
	(c, d) = map(int, input().split())
	ans += str(a[d - 1] - a[c - 1]) + '\n'
print(ans)


from sys import *
input = stdin.readline
s = input()
arr = list(s)
n = int(input())
arr2 = [0]
cc = 0
for k in range(1, len(arr)):
	if arr[k] == arr[k - 1]:
		cc += 1
	arr2.append(cc)
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	count = arr2[b - 1] - arr2[a - 1]
	print(count)


s = str(input())
n = int(input())
ans = []
sm = []
tsm = 0
sm.append(0)
for t in range(1, len(s)):
	if s[t] == s[t - 1]:
		tsm += 1
		sm.append(tsm)
	else:
		sm.append(tsm)
for i in range(n):
	(a, b) = map(int, input().split(' '))
	ans.append(sm[b - 1] - sm[a - 1])
for k in range(n):
	print(ans[k])


from sys import stdin, stdout
write = stdout.write
tokens = iter(stdin.read().split())
S = next(tokens)
tokens = map(int, tokens)
M = next(tokens)
memo = [0] * len(S)
for i in range(1, len(S)):
	memo[i] = memo[i - 1] + (1 if S[i] == S[i - 1] else 0)
ans = [str(memo[r - 1] - memo[l - 1]) for (l, r) in zip(tokens, tokens)]
write('\n'.join(ans))


import sys
DP = []

def build_rsq():
	DP.append(0)
	for x in range(1, len(string)):
		DP.append(DP[x - 1] + (string[x - 1] == string[x]))

def rsq(l, r):
	return DP[r - 1] - DP[l - 1]
string = sys.stdin.readline()
queries = int(sys.stdin.readline())
build_rsq()
for i in range(queries):
	(l, r) = map(int, sys.stdin.readline().split())
	print(rsq(l, r))


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
s = input()
p = [0] * (len(s) + 1)
for i in range(len(s) - 1):
	p[i + 1] = s[i] == s[i + 1]
for i in range(1, len(s) + 1):
	p[i] += p[i - 1]
(n,) = I()
for i in range(n):
	(l, r) = I()
	print(p[r - 1] - p[l - 1])


s = input()
n = int(input())
len_s = len(s)
list1 = [0] * len_s
ans = ''
for i in range(1, len_s):
	list1[i] = list1[i - 1] + (s[i - 1] == s[i])
for i in range(n):
	(a, b) = map(int, input().split())
	ans += str(list1[b - 1] - list1[a - 1]) + '\n'
print(ans)


c = ''
d = [0]
for i in input():
	if i == c:
		d.append(d[-1] + 1)
	else:
		d.append(d[-1])
	c = i
for i in range(int(input())):
	(l, r) = map(int, input().split())
	print(d[r] - d[l])


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		l = list(input())
		dp = [0]
		n = len(l)
		for x in range(1, n):
			if l[x] == l[x - 1]:
				dp.append(dp[-1] + 1)
			else:
				dp.append(dp[-1])
		for q in range(I()):
			(a, b) = In()
			print(dp[b - 1] - dp[a - 1])
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


from sys import stdin, stdout

def main():
	s = stdin.readline()
	t = [1 if s[i] == s[i + 1] else 0 for i in range(len(s) - 1)]
	d = [0] * (len(t) + 1)
	f = 0
	b = int(stdin.readline())
	for x in range(len(t)):
		f = f + t[x]
		d[x + 1] = f
	for x in range(b):
		ab = stdin.readline().split()
		a = int(ab[0]) - 1
		b = int(ab[1]) - 1
		stdout.write(str(d[b] - d[a]) + '\n')
main()


from sys import stdin
input = stdin.readline
seq = input()
c = [0, 0]
pre = seq[0]
counter = 0
for item in seq[1:]:
	if item == pre:
		counter += 1
	pre = item
	c.append(counter)
c.append(0)
n = int(input())
while n > 0:
	n -= 1
	[l, r] = [int(item) for item in input().split(' ')]
	print(c[r] - c[l])


from sys import stdin
x = lambda : stdin.readline()
s = x()
l = [0]
count = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		count += 1
	l.append(count)
for i in range(int(input())):
	(a, b) = map(int, x().split())
	print(l[b - 1] - l[a - 1])


class CodeforcesTask313BSolution:

	def __init__(self):
		self.result = ''
		self.string = ''
		self.m = 0
		self.queries = []

	def read_input(self):
		self.string = input()
		self.m = int(input())
		for x in range(self.m):
			self.queries.append([int(x) for x in input().split(' ')])

	def process_task(self):
		n = len(self.string)
		dp_point = [0] * n
		dp_hash = [0] * n
		if self.string[0] == '.':
			dp_point[0] = 1
		else:
			dp_hash[0] = 1
		for x in range(1, n):
			if self.string[x] == '.':
				dp_point[x] = dp_point[x - 1] + 1
				dp_hash[x] = dp_hash[x - 1]
			else:
				dp_point[x] = dp_point[x - 1]
				dp_hash[x] = dp_hash[x - 1] + 1
		for x in range(n - 1, 0, -1):
			dp_point[x] -= dp_point[x - 1]
			dp_hash[x] -= dp_hash[x - 1]
		dp_cons_point = [0] * n
		dp_cons_hash = [0] * n
		lastp = self.string[0] == '.'
		for x in range(1, n):
			if lastp and self.string[x] == '.':
				dp_cons_point[x] = dp_cons_point[x - 1] + 1
				dp_cons_hash[x] = dp_cons_hash[x - 1]
			elif not lastp and (not self.string[x] == '.'):
				dp_cons_point[x] = dp_cons_point[x - 1]
				dp_cons_hash[x] = dp_cons_hash[x - 1] + 1
			else:
				dp_cons_point[x] = dp_cons_point[x - 1]
				dp_cons_hash[x] = dp_cons_hash[x - 1]
			lastp = self.string[x] == '.'
		for query in self.queries:
			print(dp_cons_point[query[1] - 1] - dp_cons_point[query[0] - 1] + dp_cons_hash[query[1] - 1] - dp_cons_hash[query[0] - 1])

	def get_result(self):
		return self.result
Solution = CodeforcesTask313BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


def dp_builder(s):
	a = [0] * (len(s) + 1)
	c = s[0]
	count = 0
	i = 1
	while i < len(s):
		if s[i] == c:
			count += 1
		a[i + 1] = count
		c = s[i]
		i += 1
	return a
s = input()
m = int(input())
res = []
a = dp_builder(s)
for i in range(m):
	(l, r) = [int(x) for x in input().split()]
	res.append(a[r] - a[l])
print(*res, sep='\n')


s = input()
n = int(input())
ls = len(s)
dp = [0] * ls
for i in range(ls - 1):
	dp[i + 1] = dp[i] + (s[i] == s[i + 1])
ans = []
for _ in range(n):
	(a, b) = map(int, input().split())
	ans.append(dp[b - 1] - dp[a - 1])
print('\n'.join(map(str, ans)))


def main():
	a = input()
	c = 0
	b = [0]
	for k in range(len(a) - 1):
		if a[k] == a[k + 1]:
			c = c + 1
		b.append(c)
	for i in range(int(input())):
		(l, r) = map(int, input().split())
		print(b[r - 1] - b[l - 1])
main()


s = input()
n = len(s)
arr = [0] * n
for i in range(1, n):
	if s[i] == s[i - 1]:
		arr[i] = arr[i - 1] + 1
	else:
		arr[i] = arr[i - 1]
m = int(input())
ans_arr = [0] * m
for _ in range(m):
	(l, r) = [int(i) for i in input().split()]
	(l, r) = (l - 1, r - 1)
	ans = arr[r]
	if l >= 0:
		ans -= arr[l]
	ans_arr[_] = str(ans)
print('\n'.join(ans_arr))


import sys
s = '0' + input()
dp = [0] * len(s)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
m = int(sys.stdin.readline())
for i in range(m):
	(l, r) = map(int, sys.stdin.readline().split())
	sys.stdout.writelines('{}\n'.format(dp[r] - dp[l]))


s = input()
l = len(s)
arr = [0] * l
q = int(input())
ans = ''
for i in range(1, l):
	arr[i] = arr[i - 1]
	if s[i] == s[i - 1]:
		arr[i] += 1
for i in range(q):
	(l, r) = map(int, input().split())
	ans += str(arr[r - 1] - arr[l - 1]) + '\n'
print(ans)


s = input()
n = int(input())
l = len(s)
a = [0] * l
for i in range(1, l):
	a[i] = a[i - 1] + (s[i] == s[i - 1])
b = []
while n > 0:
	(k, m) = map(int, input().split())
	b.append(str(a[m - 1] - a[k - 1]))
	n -= 1
print('\n'.join(b))


s = input()
n = len(s)
num_equals = [0] * (n + 1)
for (pos, char) in enumerate(s[:len(s) - 1], 1):
	num_equals[pos] = num_equals[pos - 1] + (1 if char == s[pos] else 0)
num_queries = int(input())
solutions = [0] * num_queries
for pos in range(num_queries):
	(start, end) = map(int, input().split())
	solutions[pos] = str(num_equals[end - 1] - num_equals[start - 1])
print('\n'.join(solutions))


s = input()
t = [0] * len(s)
sol = []
for i in range(len(s) - 1):
	t[i + 1] = t[i] + (s[i] == s[i + 1])
m = int(input())
while m > 0:
	(x, y) = map(int, input().split())
	sol.append(str(t[y - 1] - t[x - 1]))
	m -= 1
print('\n'.join(sol))


a = input()
b = len(a)
x = int(input())
y = []
for i in range(x):
	y.append(list(map(int, input().split())))
z = [0]
for i in range(1, b):
	if a[i] == a[i - 1]:
		z.append(1)
	else:
		z.append(0)
tot = 0
z2 = [0]
for i in range(1, b):
	z2.append(tot + z[i])
	tot += z[i]
for i in y:
	(a1, a2) = (i[0], i[1])
	print(z2[a2 - 1] - z2[a1 - 1])


s = input()
m = int(input())
num = 0
ans = [0, 0]
n = len(s)
for i in range(n - 1):
	if s[i] == s[i + 1]:
		num += 1
	ans.append(num)
to_print = []
for i in range(m):
	(l, r) = map(int, input().split())
	to_print.append(ans[r] - ans[l])
for i in to_print:
	print(i)


from sys import stdin, stdout
s = stdin.readline()
n = int(stdin.readline())
len_s = len(s)
list1 = [0] * len_s
ans = ''
for i in range(1, len_s):
	list1[i] = list1[i - 1] + (s[i - 1] == s[i])
for i in range(n):
	(a, b) = map(int, input().split())
	ans += str(list1[b - 1] - list1[a - 1]) + '\n'
stdout.write(ans)


S = input()
N = int(input())
cum = []
for i in range(len(S) - 1):
	cum += [0]
	if S[i] == S[i + 1]:
		cum[i] = cum[i - 1] + 1
	else:
		cum[i] = cum[i - 1] + 0
for i in range(N):
	(l, r) = input().split()
	if int(l) == 1:
		print(cum[int(r) - 2])
	else:
		print(cum[int(r) - 2] - cum[int(l) - 2])


s = input()
m = int(input())
result = []
suma = []
sum = 0
suma.append(0)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		sum += 1
	suma.append(sum)
for i in range(0, m):
	q = input()
	q = q.split()
	l = int(q[0]) - 1
	r = int(q[1]) - 1
	result.append(suma[r] - suma[l])
for i in result:
	print(i)


input = __import__('sys').stdin.readline
s = list(input())
pre = [0] * len(s)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		pre[i] = pre[i - 1] + 1
	else:
		pre[i] = pre[i - 1]
n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	print(pre[r - 1] - pre[l - 1])


s = list(input())
m = int(input())
n = len(s)
b = []
c = [0] * n
for i in range(m):
	(l, r) = map(int, input().split())
	b.append((l, r))
for i in range(1, n):
	if s[i - 1] == s[i]:
		c[i] += c[i - 1] + 1
	else:
		c[i] += c[i - 1]
for (l, r) in b:
	print(c[r - 1] - c[l - 1])


s = input()
pa = [0] * len(s)
for i in range(len(pa) - 1):
	pa[i + 1] = pa[i] + (s[i] == s[i + 1])
n = int(input())
ans = ''
for i in range(n):
	(x, y) = map(int, input().split())
	ans += str(pa[y - 1] - pa[x - 1]) + '\n'
print(ans)


s = input()
n = int(input())
(l, r) = ([0 for i in range(n)], [0 for i in range(n)])
for i in range(n):
	(l[i], r[i]) = list(map(int, input().split()))
d = [0] * len(s)
for i in range(len(s) - 1):
	d[i + 1] = d[i]
	if s[i] == s[i + 1]:
		d[i + 1] = d[i] + 1
for i in range(n):
	print(d[r[i] - 1] - d[l[i] - 1])


def inp():
	return map(int, input().split())

def arr_sum():
	global sum
	for i in range(1, l):
		if s[i - 1] == s[i]:
			sum += 1
			dic.append(sum)
		else:
			dic.append(sum)
from collections import *
(s, dic, sum) = (input(), deque([0]), 0)
(l, ans) = (len(s), '')
arr_sum()
for i in range(int(input())):
	(l, r) = inp()
	k = dic[r - 1] - dic[l - 1]
	ans += str(k) + '\n'
print(ans)


import sys
inp = sys.stdin.readline
st = ' ' + inp().strip()
s = [0] * len(st)
p = [0] * len(st)
for i in range(1, len(st)):
	if st[i] == st[i - 1]:
		s[i] = 1
	p[i] = p[i - 1] + s[i]
for _ in range(int(inp())):
	(l, r) = map(int, inp().split())
	print(p[r] - p[l])


s = input()
l = []
m = int(input())
for i in range(len(s) - 1):
	if i == 0:
		l.insert(i, 0)
		if s[0] == s[1]:
			l.insert(i + 1, int(l[i - 1]) + 1)
		else:
			l.insert(i + 1, int(l[i - 1]))
	elif s[i] == s[i + 1]:
		l.insert(i + 1, int(l[i]) + 1)
	else:
		l.insert(i + 1, l[i])
for i in range(m):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	print(l[y - 1] - l[x - 1])


s = input().strip()
n = len(s)
dp = [0 for i in range(n)]
for i in range(1, n):
	if s[i] == s[i - 1]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
q = int(input())
l = []
for i in range(q):
	(p, o) = map(int, input().strip().split())
	l.append((p, o))
for j in range(q):
	print(dp[l[j][1] - 1] - dp[l[j][0] - 1])


line = input()
l = len(line)
a = [0] * l
for i in range(1, l):
	a[i] = a[i - 1] + (line[i] == line[i - 1])
m = int(input())
ans = ''
for _ in range(m):
	(l, r) = map(int, input().split())
	ans += str(a[r - 1] - a[l - 1]) + '\n'
print(ans)


s = input()
m = int(input())
n = len(s)
table = [0] * (n + 1)
for i in range(-2, -(n + 1), -1):
	table[i] = table[i + 1] + (s[i] == s[i + 1])
ans = []
for i in range(m):
	(l, r) = map(int, input().split())
	ans.append(table[l] - table[r])
for i in range(m):
	print(ans[i])


l = list(input())
o = []
t = len(l) - 1
a = [0] * t
for i in range(t):
	if l[i] == l[i + 1]:
		a[i] = 1
s = 0
b = [0]
for i in range(t):
	s += a[i]
	b += [s]
n = int(input())
for i in range(n):
	(u, v) = [int(x) for x in input().split()]
	o += [str(b[v - 1] - b[u - 1])]
print('\n'.join(o))


text = input().strip()
n = int(input())
dp = [0] * (len(text) + 1)
for i in range(1, len(text)):
	dp[i + 1] += dp[i] + (text[i] == text[i - 1])
for _ in range(n):
	(l, r) = map(int, input().split())
	print(dp[r] - dp[l])


s = ''
l = []
a = 0
for i in input():
	if s == i:
		a += 1
	l.append(a)
	s = i
for i in range(int(input())):
	(m, n) = map(int, input().split())
	print(l[n - 1] - l[m - 1])


s = input()
res = [0]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		res.append(res[-1] + 1)
	else:
		res.append(res[-1])
res.append(res[-1])
n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	print(res[r - 1] - res[l - 1])


s = input()
res = [0] * (len(s) + 1)
for i in range(len(s)):
	if s[i] == s[i - 1]:
		res[i + 1] = res[i] + 1
	else:
		res[i + 1] = res[i]
ans = []
m = int(input())
for _ in range(m):
	(l, r) = [int(i) for i in input().split()]
	ans.append(res[r] - res[l])
for i in range(len(ans)):
	print(ans[i])


s = list(input())
v = [0]
r = 0
ans = ''
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		r += 1
		v.append(r)
	else:
		v.append(r)
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	k = v[r - 1] - v[l - 1]
	ans += str(k) + '\n'
print(ans)


I = lambda : map(int, input().split())
s = input()
q = int(input())
count = 0
l = [0]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		count += 1
	l.append(count)
xs = ''
for i in range(q):
	(x, y) = I()
	xs += str(l[y - 1] - l[x - 1]) + '\n'
print(xs)


input_string = input()
m = int(input())
query = []
for i in range(0, m):
	temp = input()
	temp = temp.split(' ')
	first = int(temp[0])
	second = int(temp[1])
	query.append([first, second])
dp = [0, 0]
index = 2
for i in range(0, len(input_string) - 1):
	if input_string[i + 1] == input_string[i]:
		dp.append(dp[index - 1] + 1)
	else:
		dp.append(dp[index - 1])
	index += 1
for i in range(0, len(query)):
	print(dp[query[i][1]] - dp[query[i][0]])


import sys
import collections
import math
import functools
import itertools
import bisect
import operator
import heapq
import random
true = True
false = False
null = None
tcid = 0
tcmax = 99999999

def compute(val, func):
	return func(val)

def seq(lo, hi, step=1):
	return range(lo, hi + 1, step)

def sround(val, nd):
	return f'{val:.{nd}f}'

def ceil(a, b):
	ans = a // b
	if a % b != 0:
		ans += 1
	return ans

def perr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def line():
	ln = sys.stdin.readline().strip()
	if ln == '':
		sys.exit()
	return ln

def lines(n):
	return [line() for i in range(n)]

def split(ln=None):
	return (ln or line()).split()

def nums(o=None, parser=eval):
	if o is not None:
		if isinstance(o, int):
			o = lines(o)
		elif isinstance(o, str):
			o = split(o)
	return list(map(parser, o or split()))

def num(parser=eval):
	return parser(line())

def mainloop(tcid=1):
	s = line()
	aa = [0] * 111111
	for ii in range(1, len(s)):
		if s[ii] == s[ii - 1]:
			aa[ii] = 1
		aa[ii] += aa[ii - 1]
	m = num()
	for _ in range(m):
		(l, r) = nums(parser=int)
		print(aa[r - 1] - aa[l - 1])
while tcid < tcmax:
	tcid += 1
	mainloop(tcid)


def inp():
	return map(float, input().split())

def arr_sum():
	global sum
	for i in range(1, l):
		if s[i - 1] == s[i]:
			sum += 1
			dic.append(sum)
		else:
			dic.append(sum)
from sys import *
from collections import *
(s, dic, sum) = (input(), deque([0]), 0)
(l, ans) = (len(s), '')
arr_sum()
for i in range(int(input())):
	(l, r) = stdin.readline().split()
	(l, r) = (int(l), int(r))
	k = dic[r - 1] - dic[l - 1]
	ans += str(k) + '\n'
stdout.write(ans)


s = input()
q = int(input())
leng = len(s)
c = [0] * leng
for i in range(leng - 1):
	if s[i] == s[i + 1]:
		c[i + 1] = c[i] + 1
	else:
		c[i + 1] = c[i]
for i in range(q):
	(l, r) = map(int, input().split())
	print(c[r - 1] - c[l - 1])


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
q = input()
t = len(q)
w = int(input())
e = [0]
r = 0
for i in range(t - 1):
	if q[i] == q[i + 1]:
		r += 1
	e.append(r)
for i in range(w):
	(l, r) = map(int, input().split())
	print(e[r - 1] - e[l - 1])


from sys import stdin, stdout
input_lines = iter(stdin.read().splitlines())
string = next(input_lines).strip()
m = int(next(input_lines))
queries = []
for pair in input_lines:
	pair = pair.split()
	(a, b) = (int(pair[0]), int(pair[1]))
	par = tuple([a, b])
	queries.append(par)
DP = [0] * len(string)
count = 0
for i in range(len(string) - 1):
	if string[i + 1] == string[i]:
		count = count + 1
	DP[i + 1] = count
for query in queries:
	(l, r) = query
	print(DP[r - 1] - DP[l - 1])


s = input()
n = len(s)
count = [0] * n
for i in range(1, n):
	if s[i] == s[i - 1]:
		count[i] = count[i - 1] + 1
	else:
		count[i] = count[i - 1]
ans = []
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split(' '))
	ans.append(count[b - 1] - count[a - 1])
for i in range(m):
	print(ans[i])


m = input()
A = [0]
for i in range(1, len(m)):
	x = 0
	if m[i] == m[i - 1]:
		x = 1
	A.append(A[i - 1] + x)
Ans = ''
for i in range(int(input())):
	(l, r) = map(int, input().split())
	Ans += str(A[r - 1] - A[l - 1]) + '\n'
print(Ans)


s = input()
dp = [0] * 100005
for i in range(len(s) - 1):
	if i == 0:
		dp[i] = int(s[i] == s[i + 1])
	else:
		dp[i] = dp[i - 1] + int(s[i] == s[i + 1])
dp[len(s)] = dp[len(s) - 1]
m = int(input())
res = list()
for i in range(m):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	if r == 0 or l == r:
		res.append(0)
	elif l == 0:
		res.append(dp[r - 1])
	else:
		res.append(dp[r - 1] - dp[l - 1])
print('\n'.join(map(str, res)))


s = input()
dp = [0] * len(s)
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		dp[i + 1] = dp[i] + 1
	else:
		dp[i + 1] = dp[i]
m = int(input())
for j in range(m):
	(l, r) = map(int, input().split())
	print(dp[r - 1] - dp[l - 1])


import sys
input = sys.stdin.readline
s = input().rstrip()
n = len(s)
dp = [0] * n
for i in range(1, n):
	dp[i] = dp[i - 1]
	if s[i] == s[i - 1]:
		dp[i] += 1
for _ in range(int(input().rstrip())):
	(l, r) = map(int, input().rstrip().split())
	print(dp[r - 1] - dp[l - 1])


s = input()
m = int(input())
answer = []
counting = (len(s) + 1) * [0]
for i in range(1, len(s)):
	counting[i] = counting[i - 1] + (s[i - 1] == s[i])
for i in range(m):
	(l, r) = (int(x) for x in input().split())
	answer.append(counting[r - 1] - counting[l - 1])
print(*answer, sep='\n')


s = input()
m = int(input())
(S, cnt) = ([0], 0)
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		cnt += 1
	S.append(cnt)
for i in range(m):
	(a, b) = map(int, input().split())
	print(S[b - 1] - S[a - 1])


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
s = input()
cnt = [0] * (len(s) + 1)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		cnt[i + 1] = cnt[i] + 1
	else:
		cnt[i + 1] = cnt[i]
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print('%d\n' % (cnt[b] - cnt[a]))


s = input()
n = int(input())
a = [0] * len(s)
l = []
for i in range(len(s) - 1):
	a[i + 1] = a[i] + (s[i + 1] == s[i])
for i in range(n):
	(x, y) = map(int, input().split())
	l.append(a[y - 1] - a[x - 1])
print(*l, sep='\n')


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations, accumulate
from math import gcd, floor, inf, log2, sqrt, log10
from bisect import bisect_right, bisect_left
from statistics import mode
from string import ascii_uppercase
s = 'x' + input() + 'x'
ln = len(s) - 1
pre = []
for i in range(ln):
	if s[i] == s[i + 1]:
		pre.append(1)
	else:
		pre.append(0)
pre_sum = list(accumulate(pre))
cases = int(input())
for _ in range(cases):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	print(pre_sum[r] - pre_sum[l])


s = input()
ans = [0]
for i in range(1, len(s)):
	if s[i - 1] == s[i]:
		ans.append(ans[-1] + 1)
	else:
		ans.append(ans[-1])
m = int(input())
for i in range(m):
	(l, r) = list(map(int, input().strip().split()))
	print(ans[r - 1] - ans[l - 1])


def main():
	s = input()
	dp = [0] * len(s)
	for i in range(len(dp) - 1):
		dp[i + 1] = dp[i] + (s[i] == s[i + 1])
	ans_list = []
	for _ in range(int(input())):
		(l, r) = map(lambda x: int(x) - 1, input().split())
		ans_list.append(str(dp[r] - dp[l]))
	print('\n'.join(ans_list))
main()


s = input().strip()
l = [0] * len(s)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		l[i] = l[i - 1] + 1
	else:
		l[i] = l[i - 1]
s1 = ''
for _ in range(int(input())):
	(li, r) = map(int, input().split())
	s1 += str(l[r - 1] - l[li - 1]) + '\n'
print(s1)


s = input()
dp = [0] * (len(s) + 1)
for i in range(len(s) - 1):
	dp[i + 1] = dp[i] + (s[i] == s[i + 1])
a = ''
for i in range(int(input())):
	(l, r) = map(int, input().split())
	a += '{}\n'.format(dp[r - 1] - dp[l - 1])
print(a)


s = input()
c = 0
dp = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		c += 1
	dp.append(c)
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	print(dp[r - 1] - dp[l - 1])


st = input()
dlin = len(st)
t = [0] * dlin
ch = 1
repoto = []
for i in range(dlin - 1):
	if st[i] == st[i + 1]:
		t[i] = ch
		ch += 1
	else:
		t[i] = ch
t[dlin - 1] = ch
n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	repoto.append(t[y - 1] - t[x - 1])
for i in repoto:
	print(i)


myString = input()
n = len(myString)
dp = [0 for x in range(n)]
if myString[0] == myString[1]:
	dp[1] = 1
else:
	dp[1] = 0
for x in range(2, n):
	dp[x] = dp[x - 1]
	if myString[x] == myString[x - 1]:
		dp[x] += 1
questions = int(input())
answer = []
for i in range(questions):
	words = []
	for word in input().split():
		words.append(word)
	start = int(words[0])
	stop = int(words[1])
	start -= 1
	stop -= 1
	answer.append(dp[stop] - dp[start])
for a in answer:
	print(a)


s = input()
a = [0] * len(s)
a[0] = 0
s1 = 0
ans = ''
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		s1 += 1
	a[i] = s1
f = int(input())
for i in range(f):
	(ae1, b) = map(int, input().split())
	ans += str(a[b - 1] - a[ae1 - 1]) + '\n'
print(ans)


l = list(input())
a = [(l[i] == l[i + 1]) * 1 for i in range(len(l) - 1)]
s = [0]
su = 0
for x in a:
	su += x
	s += [su]
n = int(input())
ans = []
for _ in range(n):
	(i, j) = map(int, input().split())
	ans += [str(s[j - 1] - s[i - 1])]
print('\n'.join(ans))


from sys import stdin
z = input()
count = 0
i = 0
res = [0]
while i < len(z) - 1:
	if z[i] == z[i + 1]:
		count = count + 1
	res.append(count)
	i = i + 1
d = int(input())
while d:
	(n, k) = map(int, stdin.readline().rstrip().split(' '))
	print(res[k - 1] - res[n - 1])
	d -= 1


s = input()
n = len(s)
dp = [0] * n
dp[0] = 0
for i in range(1, n):
	dp[i] = dp[i - 1]
	if s[i] == s[i - 1]:
		dp[i] += 1
m = int(input())
for i in range(m):
	(x, y) = map(int, input().split())
	print(dp[y - 1] - dp[x - 1])


s = input()
dp = [0]
cunt = 0
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		cunt += 1
	dp.append(cunt)
n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	print(dp[r - 1] - dp[l - 1])


s = input()
arr = [0] * len(s)
for k in range(1, len(s)):
	if s[k] == s[k - 1]:
		arr[k] = arr[k - 1] + 1
	else:
		arr[k] = arr[k - 1]
for z in range(int(input())):
	(left, right) = map(int, input().split())
	left -= 1
	right -= 1
	print(arr[right] - arr[left])


s = input()
t = int(input())
ans = []
n = len(s)
clue = [0] * n
for i in range(n - 1):
	if s[i] == s[i + 1]:
		clue[i] += 1
L = [clue[0]]
for i in range(1, n):
	L.append(L[i - 1] + clue[i])
for i in range(t):
	(A, B) = input().split()
	A = int(A) - 1
	B = int(B) - 1
	r = 0
	x = L[B - 1]
	y = L[A - 1]
	if A - 1 < 0:
		y = 0
	ans.append(x - y)
for i in range(t):
	print(ans[i])


def create_lookup_table(s):
	length = len(s) - 1
	res = [1] if s[0] == s[1] else [0]
	for i in range(1, length):
		if s[i] == s[i + 1]:
			res.append(res[-1] + 1)
		else:
			res.append(res[-1])
	return res
s = input()
n = int(input())
lookup = create_lookup_table(s)
res = []
for _ in range(n):
	(l, r) = (int(i) for i in input().split())
	l -= 1
	r -= 2
	if l == 0:
		res.append(lookup[r])
	else:
		res.append(lookup[r] - lookup[l - 1])
for r in res:
	print(r)


s = input()
A = []
k = 0
A.append(0)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		k += 1
	A.append(k)
for _ in range(int(input())):
	(l, r) = [int(x) for x in input().split()]
	print(A[r - 1] - A[l - 1])


alist = list(input())
b = [0] * len(alist)
for i in range(len(alist) - 1):
	if alist[i] == alist[i + 1]:
		b[i + 1] = b[i] + 1
	else:
		b[i + 1] = b[i]
m = int(input())
qqq = []
for i in range(m):
	(l, r) = map(int, input().split())
	qqq.append(str(b[r - 1] - b[l - 1]))
print('\n'.join(qqq))


from sys import stdin, stdout
input = stdin.readline
s = input()
a = [0] * len(s)
for i in range(0, len(s) - 1):
	if s[i] == s[i + 1]:
		a[i] = 1
for i in range(1, len(s) - 1):
	a[i] = a[i] + a[i - 1]
n = int(input())
for i in range(0, n):
	(l, r) = list(map(int, input().split()))
	if l == 1:
		print(a[r - 2])
	else:
		print(a[r - 2] - a[l - 2])


def solve():
	l = list(input())
	n = len(l)
	r = [0 for i in range(n)]
	for i in range(1, n):
		r[i] = r[i - 1] + (l[i] == l[i - 1])
	for i in range(int(input())):
		(ro, c) = map(int, input().strip().split())
		print(r[c - 1] - r[ro - 1])
solve()


s = input()
m = int(input())
n = len(s)
ans = [0]
state = 0
t = 0
output = []
for i in range(1, n):
	if s[i] == s[i - 1]:
		state += 1
	ans.append(state)
for i in range(m):
	(a, b) = map(int, input().split())
	t = ans[b - 1] - ans[a - 1]
	output.append(t)
for i in output:
	print(i)


s = input()
lst = [0 for i in range(len(s))]
for i in range(1, len(s)):
	lst[i] = lst[i - 1]
	if s[i] == s[i - 1]:
		lst[i] += 1
n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	print(lst[r - 1] - lst[l - 1])


from sys import stdin, stdout
import bisect
s = stdin.readline()
m = int(stdin.readline())
dp = [0]
for i in range(1, len(s)):
	dp.append(dp[i - 1])
	if s[i - 1] == s[i]:
		dp[i] += 1
dp.append(dp[len(s) - 1])
for i in range(m):
	ans = 0
	(l, r) = [int(j) for j in stdin.readline().split()]
	ans = dp[r - 1] - dp[l - 1]
	stdout.write(str(ans) + '\n')


def solve():
	string = input()
	m = int(input())
	diff = [0 for i in range(len(string))]
	for i in range(1, len(string)):
		if string[i] == string[i - 1]:
			diff[i] = 1
	prefix = [0 for i in range(len(string))]
	for i in range(1, len(string)):
		prefix[i] = prefix[i - 1] + diff[i]
	while m:
		(l, r) = map(int, input().split())
		l -= 1
		r -= 1
		ans = prefix[r] - prefix[l]
		print(ans)
		m -= 1
solve()


def solve():
	s = input()
	n = len(s) + 1
	dp = [0] * n
	for i in range(1, n):
		dp[i] = dp[i - 1] + (s[i - 1] == s[i - 2])
	t = int(input())
	while t > 0:
		(x, y) = map(int, input().split())
		print(dp[y] - dp[x])
		t = t - 1
solve()


from sys import stdin
input = stdin.readline
a = str(input())
n = len(a)
dp = [0] * n
l = 0
for i in range(n - 1):
	if a[i] == a[i + 1]:
		l += 1
		dp[i] = l
	else:
		dp[i] = l
dp[n - 1] = dp[n - 2]
m = int(input())
for _ in range(m):
	(l, r) = list(map(int, input().split()))
	if l - 2 >= 0:
		print(dp[r - 2] - dp[l - 2])
	else:
		print(dp[r - 2])


s = input()
l = len(s)
sum_array = [0] * l
for i in range(1, l):
	sum_array[i] = sum_array[i - 1]
	if s[i] == s[i - 1]:
		sum_array[i] += 1
m = int(input())
for i in range(m):
	(li, ri) = map(int, input().split())
	print(sum_array[ri - 1] - sum_array[li - 1])


s = input()
m = int(input())
l1 = [0 for i in range(0, len(s))]
l2 = ['' for i in range(0, m)]
count = 0
for i in range(0, len(s) - 1):
	if s[i] == s[i + 1]:
		count += 1
	l1[i + 1] = count
for i in range(0, m):
	(l, r) = map(int, input().split())
	l2[i] = str(l1[r - 1] - l1[l - 1])
print('\n'.join(l2))


import sys
import io
fin = io.StringIO(sys.stdin.read())
s = fin.readline().strip()
n = len(s)
table = [0] * n
for i in range(n - 1):
	table[i] = int(s[i] == s[i + 1]) + (table[i - 1] if i > 0 else 0)
m = int(fin.readline())
for _ in range(m):
	(l, r) = map(int, fin.readline().split())
	print(table[r - 2] - (table[l - 2] if l > 1 else 0))


(arr, cnt) = ([0, 0], 0)
s = input()
n = int(input())
q = []
for _ in range(n):
	(l, r) = list(map(int, input().split()))
	q.append((l, r))
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		cnt += 1
	arr.append(cnt)
for (l, r) in q:
	print(arr[r] - arr[l])


S = input()
from sys import *
A = [0]
for i in range(1, len(S)):
	if S[i] == S[i - 1]:
		A += [A[-1] + 1]
	else:
		A += [A[-1]]
for i in range(int(input())):
	(l, r) = map(int, stdin.readline().split())
	print(A[r - 1] - A[l - 1])


s = [str(i) for i in input()]
ans = [0]
num = 0
answer = []
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		num += 1
	ans.append(num)
for i in range(int(input())):
	(l, r) = map(int, input().split())
	answer.append(str(ans[r - 1] - ans[l - 1]))
print('\n'.join(answer))


from sys import stdin, stdout

def scan(type):
	return list(map(type, stdin.readline().rstrip().split()))
(string,) = scan(str)
arr = [0] * len(string)
for i in range(1, len(string)):
	temp = arr[i - 1]
	if string[i] == string[i - 1]:
		temp += 1
	arr[i] = temp
(n,) = scan(int)
for i in range(n):
	(l, r) = scan(int)
	if l:
		l -= 1
	r -= 1
	stdout.write(str(arr[r] - arr[l]) + '\n')


s = input()
query_time = int(input())
queries = [list([int(x) - 1 for x in input().split()]) for _ in range(query_time)]
k = 0
f = [0]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		k += 1
	f.append(k)
for query in queries:
	(begin, end) = query
	repeat = f[end] - f[begin]
	print(repeat)


string = input()
lst = list(string)
m = int(input())
new_lst = []
new_lst.insert(0, 0)
out = []
count = 0
for i in range(1, len(string)):
	if lst[i] == lst[i - 1]:
		count += 1
	new_lst.append(count)
for i in range(m):
	(fnum, snum) = input().split()
	fnum = int(fnum)
	snum = int(snum)
	out.append(new_lst[snum - 1] - new_lst[fnum - 1])
for i in range(len(out)):
	print(out[i])


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return list(map(int, input().split()))

def solve(s, q):
	dp = []
	_sum = []
	for (i, c) in enumerate(s[:-1]):
		dp.append(1 if s[i] == s[i + 1] else 0)
	dp.append(0)
	_sum.append(dp[0])
	for (i, c) in enumerate(dp[1:]):
		val = _sum[i] + dp[i + 1]
		_sum.append(val)
	for query in q:
		i = query[0] - 1
		j = query[1] - 1
		if i == 0:
			print(_sum[j - 1])
		else:
			print(_sum[j - 1] - _sum[i - 1])
s = insr()
n = inp()
q = []
for i in range(n):
	q.append(inlt())
solve(s, q)


a = input()
hey = [0]
ans = 0
for i in range(1, len(a)):
	if a[i - 1] == a[i]:
		ans += 1
	hey.append(ans)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	print(hey[m - 1] - hey[n - 1])


str = input()
cnt = 0
list = [0]
for i in range(1, len(str)):
	if str[i] == str[i - 1]:
		cnt += 1
	list.append(cnt)
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	print(list[b - 1] - list[a - 1])


s = input()
state = [0 for i in range(len(s) - 1)]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		state[i] = 1
newstate = [0 for i in range(len(s) - 1)]
newstate[0] = state[0]
for i in range(1, len(s) - 1):
	newstate[i] = newstate[i - 1] + state[i]
newstate.insert(0, 0)
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	print(newstate[b - 1] - newstate[a - 1])


import itertools
import sys
a = 'x' + sys.stdin.readline()
b = list(itertools.accumulate(map(lambda i: a[i] == a[i + 1], range(len(a) - 1))))
m = int(sys.stdin.readline())
q = []
for x in range(m):
	q.append(list(map(int, sys.stdin.readline().split())))
for x in range(m):
	print(b[q[x][1] - 1] - b[q[x][0] - 1])


s = input()
len_s = len(s)
(ls, a) = ([0] * len_s, '')
for i in range(len_s - 1):
	ls[i + 1] = ls[i] + (s[i] == s[i + 1])
for _ in '0' * int(input()):
	(l, r) = map(int, input().split())
	a += str(ls[r - 1] - ls[l - 1]) + '\n'
print(a)


s = input()
m = int(input())
cnt = [0] * len(s)
ans = ''
for i in range(1, len(s)):
	cnt[i] = cnt[i - 1] + (s[i] == s[i - 1])
for i in range(m):
	(l, r) = map(int, input().strip().split(' '))
	ans += str(cnt[r - 1] - cnt[l - 1]) + '\n'
print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

def LI():
	return list(map(int, input().split()))

def I():
	return int(input())

def LS():
	return input().split()

def S():
	return input()

def main():
	s = S()
	l = [0] * len(s)
	x = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			x += 1
		l[i] += x
	l = [0] + l
	n = I()
	ans = []
	for _ in range(n):
		(a, b) = LI()
		ans.append(l[b] - l[a])
	for x in ans:
		print(x)
main()


str1 = input()
m = int(input())
dp = [0] * (len(str1) + 10)
ans = [0] * m
if str1[0] == str1[1]:
	dp[0] = 1
for i in range(1, len(str1) - 1):
	if str1[i] == str1[i + 1]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
for i in range(m):
	(a, b) = map(int, input().split())
	if a <= 1:
		ans[i] = dp[b - 2]
	else:
		ans[i] = dp[b - 2] - dp[a - 2]
print('\n'.join((str(i) for i in ans)))


s = input()
n = len(s)
count = 0
if n >= 2 and n <= 10 ** 5 and (s.count('.') + s.count('#') == n):
	m = int(input())
	a = []
	b = []
	a.append(0)
	for i in range(1, n):
		a.append(0)
		if s[i] == s[i - 1]:
			count += 1
			a[i] = count
		else:
			a[i] = count
	if m >= 1 and m <= 10 ** 5:
		for i in range(m):
			b.append(0)
			(l, r) = input().strip().split(' ')
			(l, r) = [int(l), int(r)]
			if l >= 1 and l < r and (r <= n):
				l -= 1
				r -= 1
				b[i] = a[r] - a[l]
		print(*b, sep='\n')


import sys

def write_to_stdout(res):
	sys.stdout.write('%s\n' % res)

def read_input():
	return [int(_) for _ in input().rstrip().split()]

def get_value_array(s):
	ans = [0]
	count = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			count += 1
		ans.append(count)
	return ans

def main():
	s = input()
	N = int(input())
	value_array = get_value_array(s)
	res = []
	while N > 0:
		N -= 1
		(l, r) = [int(_) for _ in input().split()]
		res.append(str(value_array[r - 1] - value_array[l - 1]))
	write_to_stdout('\n'.join(res))
main()


import sys
s = list(sys.stdin.readline().strip())
n = int(sys.stdin.readline().strip())
q = [0] * n
m = [0] * (len(s) - 1)
a = 0
for i in range(n):
	b = sys.stdin.readline().strip().split(' ')
	q[i] = (int(b[0]) - 1, int(b[1]) - 1)
for i in range(len(m)):
	if s[i] == s[i + 1]:
		a += 1
		m[i] = m[i - 1] + 1
	else:
		m[i] = m[i - 1]
for v in q:
	d = v[0] - 1
	if v[0] - 1 < 0:
		print(a - (a - m[v[1] - 1]))
	else:
		print(a - m[d] - (a - m[v[1] - 1]))


s = input()
l = len(s)
p = [0] * l
for i in range(0, l - 1):
	p[i + 1] = p[i] + (s[i] == s[i + 1])
sum = ''
for _ in range(int(input())):
	x = list(map(int, input().split()))
	sum += str(p[x[1] - 1] - p[x[0] - 1]) + '\n'
print(sum)


s = input()
m = int(input())
f = [0] * len(s)
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		f[i] = f[i - 1] + 1
	else:
		f[i] = f[i - 1]
for i in range(m):
	(l, r) = [int(x) for x in input().split()]
	print(f[r - 2] - f[l - 2])


import itertools
import sys
a = 'x' + sys.stdin.readline()
b = list(itertools.accumulate(map(lambda i: a[i] == a[i + 1], range(len(a) - 1))))
m = int(sys.stdin.readline())
for x in range(m):
	(l, r) = map(int, sys.stdin.readline().split())
	print(b[r - 1] - b[l - 1])


s = input()
q = []
m = int(input())
for i in range(m):
	q.append(list(map(int, input().split())))
a = 0
p = [0]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		a += 1
	p.append(a)
for i in range(m):
	print(p[q[i][1] - 1] - p[q[i][0] - 1])


s = input().strip()
p = [0]
c = 0
n = len(s)
for j in range(1, n):
	if s[j] == s[j - 1]:
		c = 1
	else:
		c = 0
	p.append(c + p[-1])
q = int(input())
an = []
for j in range(q):
	(l, r) = map(int, input().split())
	an.append(p[r - 1] - p[l - 1])
for j in range(q):
	print(an[j])


import sys
s = sys.stdin.readline().split()[0]
l = len(s)
if l > 100000:
	1 // 0
a = [0] * (l + 1)
for i in range(l - 1):
	a[i + 1] = a[i]
	if s[i] == s[i + 1]:
		a[i + 1] += 1
m = int(sys.stdin.readline())
for i in range(m):
	(x, y) = map(int, sys.stdin.readline().split())
	sys.stdout.write(str(a[y - 1] - a[x - 1]) + '\n')


def solve_query(query_solution, start, end):
	return query_solution[end - 1] - query_solution[start - 1]
s = input()
num_of_queries = int(input())
queries = []
for _ in range(num_of_queries):
	queries.append([int(i) for i in input().split()])
query_solution = [0] * (len(s) + 1)
for char in range(1, len(s)):
	query_solution[char] = query_solution[char - 1] + (s[char] == s[char - 1])
for query in queries:
	(start, end) = query
	print(solve_query(query_solution, start, end))


import sys
input = sys.stdin.readline

def per1(s, l):
	ans = [0] * l
	for i in range(1, l):
		if s[i - 1] == s[i]:
			ans[i - 1] = 1
	return ans

def per2(l):
	SUM = [0] * l
	c = 0
	for i in range(l):
		if ans[i] == 1:
			c += 1
		SUM[i] = c
	return SUM

def solve(a, b):
	if a == 0:
		return SUM[b]
	else:
		return SUM[b] - SUM[a - 1]
s = input()
l = len(s)
ans = per1(s, l)
SUM = per2(l)
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(solve(a - 1, b - 2))


s = input()
d = len(s)
l = [0] * d
ans = ''
n = int(input())
for i in range(d - 1):
	l[i + 1] = l[i] + (s[i] == s[i + 1])
for j in range(n):
	(a, b) = map(int, input().rstrip().split())
	ans += str(l[b - 1] - l[a - 1]) + '\n'
print(ans)


def answer(s, m, l, r):
	ans = []
	ans.append(0)
	count = 0
	for i in range(len(s) - 1):
		if s[i + 1] == s[i]:
			count += 1
		ans.append(count)
	for i in range(m):
		print(ans[r[i] - 1] - ans[l[i] - 1])
	return

def main():
	s = input()
	m = int(input())
	l = [0] * m
	r = [0] * m
	for j in range(m):
		(l[j], r[j]) = [int(i) for i in input().split()]
	answer(s, m, l, r)
main()


s = list(input())
judge = [0] * len(s)
output = []
for i in range(len(s) - 1):
	if s[i] == s[i + 1] and i != 0:
		judge[i] = judge[i - 1] + 1
	elif s[i] == s[i + 1]:
		judge[i] = 1
	elif i != 0:
		judge[i] = judge[i - 1]
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	output.append(str(judge[r - 2] - judge[l - 2]))
print('\n'.join(output))


a = input()
b = [0]
c = 0
x = int(input())
for i in range(len(a) - 1):
	if a[i] == a[i + 1]:
		c += 1
	b.append(c)
for j in range(x):
	(l, r) = map(int, input().split())
	print(b[r - 1] - b[l - 1])


magic_string = input()
query_count = int(input())
queries = []
for i in range(query_count):
	queries.append([int(x) for x in input().split()])
saved = [0]
for i in range(1, len(magic_string)):
	saved.append(saved[i - 1] + (1 if magic_string[i - 1] == magic_string[i] else 0))
for query in queries:
	print(saved[query[1] - 1] - saved[query[0] - 1])


s = input()
similarpairs = 0
dp = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		similarpairs += 1
	dp.append(similarpairs)
query = int(input())
for i in range(query):
	correspond = [int(x) for x in input().split()]
	print(dp[correspond[-1] - 1] - dp[correspond[0] - 1])


from sys import stdout
s = input()
l = len(s)
lis = [0] * l
c = 0
for i in range(1, l):
	if s[i] == s[i - 1]:
		c += 1
	lis[i] = c
ans = ''
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	ans += str(lis[r - 1] - lis[l - 1]) + '\n'
stdout.write(ans)


s = input()
t = int(input())
lr = [list(map(int, input().split())) for _ in range(t)]
dot = [0] * len(s)
ht = [0] * len(s)
dot[0] = 1 if s[0] == '.' else 0
ht[0] = 1 if s[0] == '#' else 0
for i in range(1, len(s)):
	if s[i] == s[i - 1] == '.':
		dot[i] = dot[i - 1] + 1
		ht[i] = ht[i - 1]
	elif s[i] == s[i - 1] == '#':
		ht[i] = ht[i - 1] + 1
		dot[i] = dot[i - 1]
	else:
		dot[i] = dot[i - 1]
		ht[i] = ht[i - 1]
for (l, r) in lr:
	summed = max(dot[r - 1] - dot[l - 1] + ht[r - 1] - ht[l - 1], 0)
	print(summed)


A = input()
ans = []
B = int(input())
C = len(A)
D = [0]
E = 0
for i in range(1, C):
	if A[i] == A[i - 1]:
		E += 1
	D.append(E)
for i in range(B):
	(x, y) = [int(x) for x in input().split()]
	ans.append(abs(D[x - 1] - D[y - 1]))
for i in ans:
	print(i)


import sys
sys.setrecursionlimit(10000)
s = arr = sys.stdin.readline().strip()
n = int(input())
count = [0] * len(s)
for i in range(0, len(s) - 1):
	count[i + 1] = 1 if s[i] == s[i + 1] else 0
	count[i + 1] += count[i]
for i in range(n):
	(l, r) = [int(x) for x in sys.stdin.readline().strip().split()]
	print(count[r - 1] - count[l - 1])


s = input()
dp = [0 for i in range(len(s))]
for i in range(1, len(s)):
	dp[i] += dp[i - 1] + (s[i] == s[i - 1])
queries = int(input())
res = []
for q in range(queries):
	(l, r) = map(int, input().strip().split())
	res.append(dp[r - 1] - dp[l - 1])
for ans in res:
	print(ans)


s = input()
dp = [0 for i in range(len(s))]
x = 0
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		x += 1
	dp[i] = x
n = int(input())
s = ''
for i in range(n):
	(a, b) = map(int, input().split())
	s += str(dp[b - 1] - dp[a - 1]) + chr(10)
print(s)


s = input()
numberOfQueries = int(input())
queries = [0] * numberOfQueries
for i in range(numberOfQueries):
	a = input().split(' ')
	queries[i] = (int(a[0]), int(a[1]))
ans = 0
length = len(s)
arr = []

def same(s):
	sums = 0
	count = 0
	for x in s:
		if count == 0:
			compare = x
			count += 1
		elif compare == x:
			arr.append(1 + sums)
			sums += 1
			compare = x
		else:
			arr.append(sums)
			compare = x

def find(length, array):
	start = array[0] - 2
	end = array[1] - 2
	if start == -1:
		ans = arr[end]
	else:
		ans = arr[end] - arr[start]
	print(ans)
same(s)
for x in range(numberOfQueries):
	find(length, queries[x])


s = input()
cnt_arr = [0]
for i in range(len(s) - 1):
	cnt_arr.append(cnt_arr[i] + (s[i] == s[i + 1]))
m = int(input())
res = []
for i in range(m):
	(i, j) = map(int, input().split())
	res.append(str(cnt_arr[j - 1] - cnt_arr[i - 1]))
print('\n'.join(res))


s = input()
n = len(s)
m = int(input())
a = [0] * (n + 1)
for i in range(n - 1):
	a[i + 1] = a[i] + (s[i] == s[i + 1])
ans = ''
for i in range(m):
	(l, r) = map(int, input().split())
	ans += str(a[r - 1] - a[l - 1]) + ' '
print(*ans.split(), sep='\n')


from sys import stdin, stdout

def CargarArreglo():
	caracteres = stdin.readline()
	acumulador = [0] * len(caracteres)
	for i in range(1, len(caracteres)):
		if caracteres[i - 1] == caracteres[i]:
			acumulador[i] = acumulador[i - 1] + 1
		else:
			acumulador[i] = acumulador[i - 1]
	return acumulador

def consulta(acumulador, indice):
	return acumulador[int(indice[1]) - 1] - acumulador[int(indice[0]) - 1]
acu = CargarArreglo()
for i in range(0, int(stdin.readline())):
	print(consulta(acu, stdin.readline().split(' ')))


import sys
str = sys.stdin.readline()
dp = []
dp.append(0)
a = len(str)
for i in range(1, a):
	if str[i] == str[i - 1]:
		dp.append(dp[i - 1] + 1)
	else:
		dp.append(dp[i - 1])
m = int(input())
for i in range(0, m):
	(c, d) = map(int, sys.stdin.readline().split())
	c -= 1
	d -= 1
	print(dp[d] - dp[c])


str_value = input()
similar_indices = [0] * len(str_value)
for i in range(1, len(str_value)):
	if str_value[i - 1] == str_value[i]:
		similar_indices[i] = similar_indices[i - 1] + 1
	else:
		similar_indices[i] = similar_indices[i - 1]
for i in range(0, int(input())):
	l_r = list(map(int, input().split()))
	print(similar_indices[l_r[1] - 1] - similar_indices[l_r[0] - 1])


s = input()
vetor = [0] * (len(s) + 1)
counter = 0
ant = s[0]
for i in range(len(s)):
	if s[i] != ant:
		counter += 1
		ant = s[i]
	vetor[i + 1] = counter
m = int(input())
r = []
for _ in range(m):
	(i, j) = list(map(int, input().split()))
	r.append(str(j - i - (vetor[j] - vetor[i])))
print('\n'.join(r))


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
s = input()
pre = [0] * (len(s) + 1)
for i in range(1, len(s)):
	pre[i] = pre[i - 1]
	if s[i - 1] == s[i]:
		pre[i] += 1
q = int(input())
for i in range(q):
	(a, b) = map(int, input().split())
	print(pre[b - 1] - pre[a - 1])


def main():
	s = input()
	n = len(s)
	dp = [0] * n
	for i in range(1, n):
		dp[i] = dp[i - 1]
		if s[i] == s[i - 1]:
			dp[i] += 1
	ans = []
	m = int(input())
	for i in range(m):
		(l, r) = map(int, input().split())
		ans.append(dp[r - 1] - dp[l - 1])
	for i in range(m):
		print(ans[i])
main()


s = input()
m = int(input())
t = []
for i in range(m):
	t.append([int(x) for x in input().split()])
l = [0] * (len(s) + 1)
for j in range(len(s) - 1):
	if s[j] == s[j + 1]:
		l[j + 2] = 1
for i in range(1, len(s) + 1):
	l[i] += l[i - 1]
for x in t:
	print(l[x[1]] - l[x[0]])


s = input()
ans = []
res = [0] * (len(s) + 1)
for i in range(len(s)):
	if s[i] == s[i - 1]:
		res[i + 1] = res[i] + 1
	else:
		res[i + 1] = res[i]
for _ in range(int(input())):
	(l, r) = [int(i) for i in input().split()]
	ans.append(str(res[r] - res[l]))
print('\n'.join(ans))


v = input()
ary = [0] * (len(v) + 1)
ans = ''
for i in range(1, len(v)):
	ary[i] = ary[i - 1] + (v[i - 1] == v[i])
for i in range(int(input())):
	(a, b) = map(int, input().split())
	ans += str(ary[b - 1] - ary[a - 1]) + '\n'
print(ans)


from sys import stdin, stderr
from bisect import bisect

def readInts():
	return map(int, stdin.readline().strip().split())

def print_err(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def run():
	s = input().strip()
	changes = []
	n = len(s)
	for ix in range(n - 1):
		if s[ix] != s[ix + 1]:
			changes.append(2 * ix + 1)
	for _ in range(list(readInts())[0]):
		(lhs, rhs) = readInts()
		count_low = bisect(changes, (lhs - 1) * 2)
		count_high = bisect(changes, (rhs - 1) * 2)
		print(rhs - lhs - (count_high - count_low))
run()


import os.path
from math import gcd, floor, ceil
from collections import *
from bisect import *
import sys
from random import *
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
s = st()
n = len(s)
m = inp()
l = [li() for i in range(m)]
ans = [0 for i in range(n + 1)]
for i in range(1, n):
	ans[i] = ans[i - 1]
	if s[i - 1] == s[i]:
		ans[i] += 1
ans[-1] = ans[-2]
for i in l:
	print(ans[i[1] - 1] - ans[i[0] - 1])


import os
import sys
from itertools import accumulate
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
readint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
readints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
readstr = lambda : sys.stdin.readline().rstrip('\r\n')
readstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
readarri = lambda : [int(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
readarrs = lambda : [str(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]

def solve():
	s = readstr()
	n = len(s)
	pre = list(accumulate([1] + [1 if s[i] == s[i - 1] else 0 for i in range(1, n)]))
	for _ in range(readint()):
		(l, r) = readints()
		print(pre[r - 1] - pre[l - 1])

def main():
	t = 1
	for _ in range(t):
		solve()
main()


import sys
import bisect
import math
import itertools

def get_line():
	return list(map(int, sys.stdin.readline().strip().split()))

def in1():
	return int(input())

def solve(s1):
	t1 = len(s1)
	if s1[0] == s1[1]:
		d[0] = 1
	else:
		d[0] = 0
	for i in range(1, t1):
		if s1[i] == s1[i - 1]:
			d[i] = d[i - 1] + 1
		else:
			d[i] = d[i - 1]
d = {}
s = list(str(input()))
solve(s)
n = in1()
for i in range(n):
	(x, y) = get_line()
	print(d[y - 1] - d[x - 1])


s = input()
n = int(input())
l = len(s)
a = [0] * l
ans = ''
for i in range(l - 1):
	a[i + 1] = a[i] + (s[i + 1] == s[i])
for i in range(n):
	(j, k) = map(int, input().split())
	ans += str(a[k - 1] - a[j - 1]) + '\n'
print(ans)


import sys
s = list(sys.stdin.readline().strip())
numberOfQueries = int(sys.stdin.readline().strip())
queries = [0] * numberOfQueries
for i in range(numberOfQueries):
	a = input().split(' ')
	queries[i] = (int(a[0]), int(a[1]))
ans = 0
length = len(s)
arr = []

def same(s):
	sums = 0
	count = 0
	for x in s:
		if count == 0:
			compare = x
			count += 1
		elif compare == x:
			arr.append(1 + sums)
			sums += 1
			compare = x
		else:
			arr.append(sums)
			compare = x

def find(length, array):
	start = array[0] - 2
	end = array[1] - 2
	if start == -1:
		ans = arr[end]
	else:
		ans = arr[end] - arr[start]
	print(ans)
same(s)
for x in range(numberOfQueries):
	find(length, queries[x])


s = input()
m = int(input())
prev = s[0]
dp = [0]
count = 0
for ss in s[1:]:
	if ss == prev:
		count += 1
	dp.append(count)
	prev = ss
for _ in range(m):
	(l, r) = [int(x) for x in input().split(' ')]
	if l > 1:
		count = dp[r - 1] - dp[l - 1]
	else:
		count = dp[r - 1]
	print(count)


import itertools as I
from sys import stdin as S
a = 'x' + S.readline()
b = list(I.accumulate(map(lambda i: a[i] == a[i + 1], range(len(a) - 1))))
for x in range(int(S.readline())):
	(l, r) = map(int, S.readline().split())
	print(b[r - 1] - b[l - 1])


def prog():
	s = input()
	(mas, n, a) = ([], len(s), 0)
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			a += 1
		mas.append(a)
	from sys import stdin
	m = int(stdin.readline())
	for i in range(m):
		(l, r) = map(int, stdin.readline().split())
		if l == 1:
			print(mas[r - 2])
		else:
			print(mas[r - 2] - mas[l - 2])
prog()


import sys
f = sys.stdin
s = f.readline().rstrip('\r\n')
s = 't' + s + 't'
m = int(f.readline().rstrip('\r\n'))
dp = [0] * len(s)
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
for i in range(m):
	(l, r) = map(int, f.readline().rstrip('\r\n').split())
	print(dp[r - 1] - dp[l - 1])


from sys import stdin, stdout
s = input()
a = [0] * len(s)
count = 0
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		count += 1
	a[i] = count
c = ''
for i in range(int(input())):
	(x, y) = map(int, input().split())
	c += str(a[y - 1] - a[x - 1]) + '\n'
stdout.write(c)


n = input()
s = [0] * len(n)
z = 0
for i in range(len(n) - 1):
	if n[i] == n[i + 1]:
		z += 1
		s[i + 1] = z
	else:
		s[i + 1] = s[i]
mamam = int(input())
for i in range(mamam):
	(l, m) = map(int, input().split())
	print(s[m - 1] - s[l - 1])


(st, m) = (input(), int(input()))
sp = [0]
for i in range(1, len(st)):
	sp.append(sp[-1] + (st[i - 1] == st[i]))
rez = ''
for _ in range(m):
	(a, b) = map(int, input().split())
	rez += str(sp[b - 1] - sp[a - 1]) + '\n'
print(rez)


import sys

def solve():
	s = input()
	m = int(input())
	mem = [0] * (len(s) + 1)
	res = list()
	for i in range(1, len(s) + 1):
		mem[i] = mem[i - 1] + (1 if i < len(s) and s[i - 1] == s[i] else 0)
	for query in range(m):
		(l, r) = map(int, input().split())
		res.append(mem[r - 1] - mem[l - 1])
	print('\n'.join(map(str, res)))
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
solve()


from sys import stdin, stdout
linea = str(stdin.readline())
cant = int(stdin.readline())
cont = 0
dp = [0] * len(linea)
for i in range(1, len(linea)):
	if linea[i] == linea[i - 1]:
		cont += 1
	dp[i] = cont
for i in range(cant):
	(a, b) = [int(n) for n in stdin.readline().strip().split()]
	stdout.write(str(dp[b - 1] - dp[a - 1]) + '\n')


str1 = input()
li1 = [0] * len(str1)
li = []
count = 0
for i in range(len(str1) - 1):
	count += str1[i] == str1[i + 1]
	li1[i] = count
a = int(input())
for _ in range(a):
	(x, y) = map(int, input().split())
	li.append(li1[y - 2] - li1[x - 2])
for i in li:
	print(i)


sequence = input()
length = len(sequence)
m = int(input())
dp = [0] * length
if sequence[0] == sequence[1]:
	dp[1] = 1
for i in range(1, length - 1):
	if sequence[i] == sequence[i + 1]:
		dp[i + 1] = dp[i] + 1
	else:
		dp[i + 1] = dp[i]
ans = []
for fake_i in range(m):
	(l, r) = [int(x) for x in input().split()]
	ans.append(dp[r - 1] - dp[l - 1])
print('\n'.join(map(str, ans)))


input = __import__('sys').stdin.readline
s = list(input())
sums = [0] * len(s)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		sums[i] = sums[i - 1] + 1
	else:
		sums[i] = sums[i - 1]
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	print(sums[r - 1] - sums[l - 1])


s = input()
count = 0
dp = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		count += 1
	dp.append(count)
m = int(input())
lst_ans = []
for i in range(m):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	lst_ans.append(dp[r] - dp[l])
for ele in lst_ans:
	print(ele)


s = input()
m = int(input())
l = [0] * 100005
cnt = 0
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		cnt = cnt + 1
	l[i] = cnt
for i in range(1, m + 1):
	(a, b) = map(int, input().split())
	print(l[b - 1] - l[a - 1])


def solution(s, n, requests):
	d = [0 for _ in range(n)]
	for i in range(1, n):
		if s[i] == s[i - 1]:
			d[i] = d[i - 1] + 1
		else:
			d[i] = d[i - 1]
	for req in requests:
		i = req[0] - 1
		j = req[1] - 1
		print(d[j] - d[i])
s = input()
n = int(input())
requests = []
for _ in range(n):
	requests.append(list(map(int, input().split())))
solution(s, len(s), requests)


s = input()
flags = (int(c1 == c2) for (c1, c2) in zip(s, s[1:]))
psums = [0] * len(s)
ssums = [0] * len(s)
for (i, v) in enumerate(flags):
	psums[i + 1] = psums[i] + v
resp = []
for _ in range(int(input())):
	(i, j) = map(int, input().split())
	resp.append(psums[j - 1] - psums[i - 1])
print('\n'.join(map(str, resp)))


l = input()
a = [0]
z = 0
x = int(input())
for i in range(len(l) - 1):
	if l[i] == l[i + 1]:
		z += 1
	a.append(z)
for j in range(x):
	(n, m) = map(int, input().split())
	print(a[m - 1] - a[n - 1])


string = ' ' + input() + ' '
out = []
ans = [0] * len(string)
for i in range(1, len(string) - 1):
	ans[i] = ans[i - 1] + 1 if string[i] == string[i + 1] else ans[i - 1]
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	out.append(ans[r - 1] - ans[l - 1])
print('\n'.join(map(str, out)))


from itertools import accumulate
s = input()
n = int(input())
req = [map(int, input().split()) for _ in range(n)]
a = [0] + list(accumulate([1 if s[i] == s[i + 1] else 0 for i in range(len(s) - 1)] + [0]))
for (l, r) in req:
	print(a[r - 1] - a[l - 1])


s = input()
ans = []
q = int(input())
n = len(s)
l = [0]
x = 0
for i in range(1, n):
	if s[i] == s[i - 1]:
		x += 1
	l.append(x)
for i in range(q):
	k = list(map(int, input().split()))
	a = k[0]
	b = k[1]
	ans.append(l[b - 1] - l[a - 1])
for i in ans:
	print(i)


s = input()
n = len(s)
dp = [0] * n
for i in range(n - 1):
	dp[i + 1] = dp[i] + (s[i + 1] == s[i])
ans = ''
T = int(input())
for i in range(T):
	(l, r) = map(int, input().split())
	if i != T - 1:
		ans += str(dp[r - 1] - dp[l - 1]) + '\n'
	else:
		ans += str(dp[r - 1] - dp[l - 1])
print(ans)


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

def read_int():
	return read_ints()[0]

def solve():
	s = input()
	n = len(s)
	pr = [0] * (n + 1)
	for i in range(n - 1):
		value = 1 if s[i] == s[i + 1] else 0
		pr[i + 1] = pr[i] + value
	q = read_int()
	answers = [0] * q
	for query_index in range(q):
		(left, right) = read_ints()
		ans = pr[right - 1] - pr[left - 1]
		answers[query_index] = ans
	print('\n'.join([str(ans) for ans in answers]))
solve()


s = ' ' + input()
pref = [0] * len(s)
for i in range(1, len(s)):
	a = 1 if s[i] == s[i - 1] else 0
	pref[i] = pref[i - 1] + a
m = int(input())
res = [0] * m
for i in range(m):
	(l, r) = map(int, input().split())
	res[i] = pref[r] - pref[l]
print('\n'.join(map(str, res)))


n = input()
s = [0]
c = 0
for u in range(len(n) - 1):
	if n[u] == n[u + 1]:
		c += 1
		s += [c]
	else:
		s += [c]
s += [0]
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	print(s[r - 1] - s[l - 1])


a = input()
w = [0]
(z, j) = (0, 1)
for i in range(1, len(a)):
	if a[i] == a[i - 1]:
		z += 1
	w.append(z)
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(w[b - 1] - w[a - 1])


s = input()
li = []
x = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		x += 1
	li.append(x)
m = int(input())
for i in range(m):
	(l, m) = map(int, input().split())
	if l == 1:
		print(li[m - 2])
	else:
		print(li[m - 2] - li[l - 2])


s = input().strip()
n = len(s)
prefix_1 = [0 for _ in range(n)]
prefix_2 = [0 for _ in range(n)]
for i in range(n - 1):
	if s[i] == s[i + 1]:
		if s[i] == '.':
			prefix_1[i] += 1
		else:
			prefix_2[i] += 1
prefix_1.insert(0, 0)
prefix_2.insert(0, 0)
for i in range(1, n + 1):
	prefix_1[i] += prefix_1[i - 1]
	prefix_2[i] += prefix_2[i - 1]
ans = []
q = int(input())
for _ in range(q):
	(l, r) = map(int, input().split())
	ans_1 = prefix_1[r - 1] - prefix_1[l - 1]
	ans_2 = prefix_2[r - 1] - prefix_2[l - 1]
	ans.append(ans_1 + ans_2)
ans = '\n'.join([str(i) for i in ans])
print(ans)


q = input()
m = int(input())
lista = []
for i in range(m):
	x = input().split()
	lista.append([int(x[0]) - 1, int(x[1]) - 1])
diccionario = {(0, 0): 0}
for i in range(len(q) - 1):
	if q[i] == q[i + 1]:
		diccionario[0, i + 1] = diccionario[0, i] + 1
	else:
		diccionario[0, i + 1] = diccionario[0, i]

def responder(x, y):
	a = diccionario.get((0, x))
	b = diccionario.get((0, y))
	return b - a
for i in lista:
	print(responder(i[0], i[1]))


s = input()
n = int(input())
mat = [0] * len(s)
for i in range(1, len(s)):
	mat[i] = mat[i - 1] + (s[i] == s[i - 1])
res = ''
for i in range(n):
	(b, e) = map(int, input().split())
	res += str(mat[e - 1] - mat[b - 1]) + '\n'
print(res)


s = str(input())
m = int(input())
L = [list(map(int, input().split())) for _ in range(m)]
n = len(s)
T = [0 for _ in range(n)]
for i in range(1, n):
	T[i] = T[i - 1]
	if s[i] == s[i - 1]:
		T[i] += 1
for i in range(m):
	print(T[L[i][1] - 1] - T[L[i][0] - 1])


s = input()
m = int(input())
l1 = [0 for i in range(0, len(s))]
count = 0
for i in range(0, len(s) - 1):
	if s[i] == s[i + 1]:
		count += 1
	l1[i + 1] = count
for i in range(0, m):
	(l, r) = map(int, input().split())
	print(l1[r - 1] - l1[l - 1])


import sys
import math
import collections
input = sys.stdin.readline
s = input()
pref = [0]
c = 0
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		c += 1
	pref.append(c)
pref.pop
m = int(input())
for i in range(m):
	(l, r) = (int(i) for i in input().split())
	print(pref[r - 1] - pref[l - 1])


s = input()
x = [0] * len(s)
if s[0] == s[1]:
	x[0] = 1
for i in range(1, len(s) - 1):
	x[i] = x[i - 1]
	if s[i] == s[i + 1]:
		x[i] += 1
if len(x) > 1:
	x[len(s) - 1] = x[len(s) - 2]
m = int(input())
aans = ''
for i in range(m):
	(l, r) = map(int, input().split())
	ans = x[r - 1]
	if l > 1:
		ans -= x[l - 2]
	if r == 1 and x[r - 1] > 0 or x[r - 1] - x[r - 2] > 0:
		ans -= 1
	aans += str(ans) + '\n'
print(aans)


s = ' ' + input()
m = int(input())
q = [tuple(map(int, input().split())) for _ in range(m)]
A = [0]
for i in range(1, len(s) - 1):
	A.append(A[-1] + (s[i + 1] == s[i]))
for (a, b) in q:
	print(A[b - 1] - A[a - 1])


def func(s, ls):
	A = [-1 for i in range(ls)]
	S = [0 for i in range(ls)]
	for i in range(ls - 1):
		if s[i] == s[i + 1]:
			A[i] = 1
		else:
			A[i] = 0
		if i != 0:
			S[i] = S[i - 1] + A[i - 1]
	A[ls - 1] = 0
	S[ls - 1] = S[ls - 2] + A[ls - 2]
	return S

def solve(s, ans, ls, S):
	(l_i, r_i) = [int(x) for x in input().split()]
	value = S[r_i - 1] - S[l_i - 1]
	ans.append(value)
	return
s = input()
ls = len(s)
S = func(s, ls)
n = int(input())
ans = []
for i in range(n):
	solve(s, ans, ls, S)
for ele in ans:
	print(ele)


n = input()
dp = [0] * len(n)
m = int(input())
for i in range(len(n) - 1):
	if n[i] == n[i + 1]:
		dp[i + 1] = dp[i] + 1
	else:
		dp[i + 1] = dp[i]
for i in range(m):
	(m1, m2) = map(int, input().split())
	a = dp[m2 - 1] - dp[m1 - 1]
	print(a)


import sys
f = sys.stdin
s = f.readline()
f.readline()
count = [0]
t = ''
q = [map(int, i.split()) for i in f.read().strip().split('\n')]

def solve():
	global t
	for i in s:
		if i == t:
			count.append(count[-1] + 1)
		else:
			count.append(count[-1])
		t = i
	for i in q:
		(l, r) = i
		print(count[r] - count[l])
solve()


s = input()
lst = list()
count = 0
for i in range(len(s) - 1):
	lst.append(count)
	if s[i] == s[i + 1]:
		count += 1
lst.append(count)
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	print(lst[r - 1] - lst[l - 1])


s = input()
a = [0]
b = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		b += 1
	a.append(b)
m = int(input())
o = []
for i in range(m):
	(l, r) = map(int, input().split())
	o.append(str(a[r - 1] - a[l - 1]))
print('\n'.join(o))


s = input()
arr = [0] + [0] * (len(s) - 1)
c = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		c += 1
		arr[i + 1] = c
	else:
		arr[i + 1] = c
x = int(input())
for i in range(x):
	(l, r) = map(int, input().split())
	print(arr[r - 1] - arr[l - 1])


s = input()
m = int(input())
n = len(s)
a = [0] * n
a[0] = 0
for i in range(n):
	a[i] = a[i - 1] + (s[i] == s[i - 1])
for j in range(m):
	(x, y) = map(int, input().split())
	print(a[y - 1] - a[x - 1])


import sys
f = sys.stdin.readline
s = f().strip()
n = len(s)
pre = [0] * n
for i in range(1, n):
	if s[i] == s[i - 1]:
		pre[i] += pre[i - 1] + 1
	else:
		pre[i] = pre[i - 1]
m = int(f().strip())
while m > 0:
	(l, r) = map(int, f().strip().split())
	l -= 1
	r -= 1
	if l == r:
		print(0)
		continue
	if l != 0:
		if s[l] == s[l - 1]:
			print(pre[r] - pre[l - 1] - 1)
		else:
			print(pre[r] - pre[l - 1])
	else:
		print(pre[r])
	m -= 1


s = input()
L = [s[i] for i in range(len(s))]
A = []
ListOfSum = [0]
for i in range(len(L) - 1):
	if L[i] == L[i + 1]:
		ListOfSum.append(ListOfSum[i] + 1)
	else:
		ListOfSum.append(ListOfSum[i])
m = int(input())
for i in range(m):
	Z = [int(t) for t in input().split()]
	A.append(ListOfSum[Z[1] - 1] - ListOfSum[Z[0] - 1])
for i in range(m):
	print(A[i])


from sys import stdin
input = stdin.readline
OUT = []

def write(item):
	if type(item) is int:
		OUT.append(str(item))
	elif type(item) is list:
		if type(item[0]) is int:
			OUT.append(' '.join(map(str, item)))
		else:
			OUT.append(' '.join(item))
	else:
		OUT.append(item)
GI = lambda : int(input())
GS = lambda : input()[:-1]
gi = lambda : list(map(int, input().split()))
gs = lambda : input().split()
psa = [0]
s = p = 0
for i in input():
	if i == p:
		s += 1
	else:
		p = i
	psa.append(s)
for i in range(int(input())):
	(l, r) = map(int, input().split())
	write(psa[r] - psa[l])
print('\n'.join(OUT))


def main():
	s = input()
	n = int(input())
	res = [0]
	for i in range(1, len(s)):
		res.append(res[i - 1] + (s[i] == s[i - 1]))
	for _ in range(n):
		(l, r) = map(int, input().split())
		print(res[r - 1] - res[l - 1])
main()


s = input()
a = [0] * len(s)
m = int(input())
queries = []
maxi = 0
for i in range(m):
	(l, r) = [int(x) for x in input().split()]
	queries.append((l, r))
	maxi = max(maxi, r)
for i in range(1, maxi):
	a[i] = a[i - 1]
	if s[i] == s[i - 1]:
		a[i] += 1
for q in queries:
	print(a[q[1] - 1] - a[q[0] - 1])


s = input()
out = 0
list = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		out += 1
	list.append(out)
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	print(list[b - 1] - list[a - 1])


s = input()
lis = []
for t in s:
	lis.append(t)
m = len(s)
n = int(input())
ans = [0] * m
p = 0
for i in range(m - 1):
	if lis[i] == lis[i + 1]:
		p += 1
	ans[i + 1] = p
for j in range(n):
	(a, b) = map(int, input().split())
	print(ans[b - 1] - ans[a - 1])


from sys import stdin, stdout
input = stdin.readline
s = input()[:-1]
n = len(s)
dp = [0] * n
for i in range(1, n):
	if s[i - 1] == s[i]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
for i in range(int(input())):
	(l, r) = map(int, input().split())
	stdout.write(str(dp[r - 1] - dp[l - 1]))
	stdout.write('\n')


s = input()
t = int(input())
l = [0] * 100001
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		l[i + 1] = l[i] + 1
	else:
		l[i + 1] = l[i]
for i in range(t):
	(n, m) = map(int, input().split())
	coN = 0
	coN = l[m] - l[n]
	print(coN)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
s = list(input())
ls = [0] * len(s)
cnt = 0
for i in range(1, len(s)):
	if s[i - 1] == s[i]:
		cnt += 1
	ls[i] = cnt
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	if ls[r - 1] > ls[l - 1]:
		print(ls[r - 1] - ls[l - 1])
	else:
		print(0)


import sys
string = sys.stdin.readline()
queries = int(sys.stdin.readline())
prefix_arr = [0]
cnt = 0
ans = 0
while cnt < len(string) - 1:
	if string[cnt] == string[cnt + 1]:
		ans += 1
	prefix_arr.append(ans)
	cnt += 1
z = len(prefix_arr)
for x in range(queries):
	(l, r) = map(int, sys.stdin.readline().split())
	if r - 1 < z:
		sys.stdout.write(str(prefix_arr[r - 1] - prefix_arr[l - 1]) + '\n')
	else:
		sys.stdout.write(str(prefix_arr[~(l - 1)]) + '\n')


S = input()
N = len(S)
a = [0] * (N + 1)
count = i = 0
while i < N - 1:
	a[i + 1] = count
	if S[i] == S[i + 1]:
		count += 1
	i += 1
a[i + 1] = count
M = int(input())
for i in range(M):
	(l, r) = map(int, input().split())
	print(a[r] - a[l])


from sys import stdin
x = lambda : stdin.readline()
s = x()
dp = [0]
n = len(s)
c = 0
for i in range(1, n):
	if s[i] == s[i - 1]:
		c = c + 1
	dp.append(c)
q = int(input())
for i in range(q):
	(l, r) = map(int, input().split())
	print(dp[r - 1] - dp[l - 1])


s = input()
prev = ' '
x = [0]
count = 0
for letter in s:
	if letter == prev:
		count += 1
	x.append(count)
	prev = letter
m = int(input())
output = list()
for i in range(m):
	(l, r) = (int(_) for _ in input().split(' '))
	output.append(str(x[r] - x[l]))
print('\n'.join(output))


query = input()
cases = int(input())
ans = []
equals_controller = 0
equals_next = [0] * (len(query) - 1)
controller = 0
while controller < len(query) - 1:
	if query[controller] == query[controller + 1]:
		equals_controller += 1
	equals_next[controller] = equals_controller
	controller += 1
equals_next.insert(0, 0)
for case in range(cases):
	(l, r) = map(int, input().split())
	result = equals_next[r - 1] - equals_next[l - 1]
	ans.append(result)
for answer in ans:
	print(answer)


import os
s = '0' + input()
cnt = 0
A = [0]
for i in range(1, len(s) - 1):
	if s[i] == s[i + 1]:
		cnt += 1
	A.append(cnt)
m = int(input())
res = []
for query in range(m):
	(l, r) = map(int, input().split())
	res.append(str(A[r - 1] - A[l - 1]))
os.write(1, '\n'.join(res).encode())


s = input()
a = [0] * len(s)
sol = ''
for x in range(1, len(s)):
	a[x] = a[x - 1] + (s[x] == s[x - 1])
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	sol += str(a[r - 1] - a[l - 1]) + '\n'
print(sol)


from fileinput import *
data = []
for line in input():
	if lineno() == 1:
		s = line.strip()
	if lineno() == 2:
		m = int(line.strip())
	if lineno() >= 3 and lineno() < 3 + m:
		data += [list(map(int, line.split()))]
slen = len(s)
a = [0] * slen
count = 0
for i in range(1, slen):
	if s[i] == s[i - 1]:
		count += 1
	a[i] = count
for [l, r] in data:
	ll = l - 1
	rr = r - 1
	print(a[rr] - a[ll])


string = input()
nqueries = int(input())
queries = []
for _ in range(nqueries):
	(start, end) = input().split()
	start = int(start)
	end = int(end)
	queries.append((start, end))
memo = [0]
succ_result = 0
for i in range(1, len(string)):
	if string[i] == string[i - 1]:
		succ_result += 1
	memo.append(succ_result)
for q in queries:
	print(memo[q[1] - 1] - memo[q[0] - 1])


s = input()
pref = [0]
for i in range(len(s) - 2 + 1):
	if s[i] == s[i + 1]:
		pref.append(1 + pref[-1])
	else:
		pref.append(pref[-1])
ans = []
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	ans.append(pref[r] - pref[l])
print('\n'.join(list(map(str, ans))))


sign = [str(x) for x in input()]
n = len(sign)
record = [0] * n
for i in range(1, n):
	if sign[i] == sign[i - 1]:
		record[i] = record[i - 1] + 1
	else:
		record[i] = record[i - 1]
m = int(input())
ans = []
for i in range(m):
	(l, r) = map(int, input().split())
	ans.append(record[r - 1] - record[l - 1])
for i in range(m):
	print(ans[i])


string = input()
n = int(input())
c = [0] * len(string)
k = 0
for i in range(1, len(string)):
	if string[i] == string[i - 1]:
		k += 1
	c[i] = k
answer = ''
for t in range(n):
	(l, r) = map(int, input().split())
	answer += str(c[r - 1] - c[l - 1]) + '\n'
print(answer)


from sys import stdin, stdout
import bisect

def st():
	return list(stdin.readline())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(a, b) = mp()
	print(l[b - 1] - l[a - 1])
s = st()
l = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		l.append(l[i - 1] + 1)
	else:
		l.append(l[i - 1])
for _ in range(inp()):
	solve()


s = list(input(''))
n = len(s)
m = int(input(''))
query = []
for i in range(m):
	query.append(list(map(int, input().split())))
dp = [0] * n
for i in range(n - 1):
	if s[i] == s[i + 1]:
		dp[i] = 1
dp1 = [0] * n
dp1[0] = dp[0]
for i in range(1, n):
	dp1[i] = dp1[i - 1] + dp[i]
for j in query:
	x = j[0]
	y = j[1]
	if y == x + 1:
		print(dp[x - 1])
	elif x == 1:
		print(dp1[y - 2])
	else:
		print(dp1[y - 2] - dp1[x - 2])


string_input = input().strip()
m = int(input())
queries = []
for i in range(m):
	line = input().strip().split(' ')
	queries.append([int(line[0]) - 1, int(line[1]) - 1])
counters = [0]
for i in range(1, len(string_input)):
	if string_input[i - 1] == string_input[i]:
		counters.append(counters[i - 1] + 1)
	else:
		counters.append(counters[i - 1])
for (x, y) in queries:
	print(counters[y] - counters[x])


s = input()
p = [0] * (len(s) + 10)
for i in range(2, len(s) + 1):
	p[i] = p[i - 1] + (1 if s[i - 1] == s[i - 2] else 0)
m = int(input())
for i in range(m):
	(li, ri) = [int(x) for x in input().split()]
	print(p[ri] - p[li])


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def main():
	s = input()
	dp = [0] * (len(s) + 1)
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			dp[i] = 1 + dp[i - 1]
		else:
			dp[i] = dp[i - 1]
	for tc in range(int(input())):
		(l, r) = get_ints()
		l -= 1
		r -= 1
		print(dp[r] - dp[l])
main()


s = input()
consecutives_sum = [0]
for i in range(len(s) - 1):
	consecutives_sum.append(consecutives_sum[-1] + (s[i] == s[i + 1]))
result = ''
for i in range(int(input())):
	(l, r) = [int(i) for i in input().split()]
	result += str(consecutives_sum[r - 1] - consecutives_sum[l - 1]) + '\n'
print(result)


s = input()
ans_input = ''
ans = [0] * len(s)
for i in range(len(s) - 1):
	ans[i + 1] = ans[i] + (s[i] == s[i + 1])
request_count = int(input())
for _ in range(request_count):
	(start, end) = list(map(int, input().split()))
	ans_input += str(ans[end - 1] - ans[start - 1]) + '\n'
print(ans_input)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
sequence = read_str() + ' '
lens = len(sequence)
cnts = [0] * lens
lens -= 1
for i in range(lens):
	cnts[i + 1] = cnts[i] + (sequence[i] == sequence[i + 1])
nb_query = read_int()
for _ in range(nb_query):
	(x, y) = read_ints()
	print(cnts[y - 1] - cnts[x - 1])


s = input()
aux = [0] * len(s)
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		aux[i + 1] = 1
for i in range(len(aux) - 2):
	aux[i + 2] = aux[i + 1] + aux[i + 2]
res = []
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	res.append(aux[b - 1] - aux[a - 1])
for i in range(len(res)):
	print(res[i])


a = input()
b = [0]
c = 0
x = int(input())
for i in range(len(a) - 1):
	if a[i] == a[i + 1]:
		c += 1
	b.append(c)
for j in range(x):
	(n, m) = map(int, input().split())
	print(b[m - 1] - b[n - 1])


s = input() + ' '
length = len(s) - 1
p = []
c = [0]
toplam = 0
answer = ''
for i in range(length):
	p.append(0)
	if s[i] == s[i + 1]:
		p[i] = 1
for i in range(length):
	if p[i] == 1:
		toplam += 1
	c.append(0)
	c[i + 1] = toplam
n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	answer += str(c[r - 1] - c[l - 1]) + '\n'
print(answer)


from sys import stdin, stdout
s = stdin.readline()
f = [0] * 100003
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		f[i + 1] = f[i] + 1
	else:
		f[i + 1] = f[i]
n = int(stdin.readline())
for _ in range(n):
	(l, r) = map(int, stdin.readline().split())
	ans = f[r - 1] - f[l - 1]
	stdout.write(str(ans) + '\n')


s = input()
dp = [0]
q = int(input())
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		dp.append(dp[-1] + 1)
	else:
		dp.append(dp[-1])
for _ in range(q):
	(l, r) = map(int, input().split())
	print(dp[r - 1] - dp[l - 1])


string = input()
array = [0]
for i in range(1, len(string)):
	if string[i - 1] == string[i]:
		array.append(array[i - 1] + 1)
	else:
		array.append(array[i - 1])
m = int(input())
list1 = []
for j in range(m):
	a = input().split(' ')
	a = list(map(int, a))
	list1.append(a)
for l in list1:
	print(array[l[1] - 1] - array[l[0] - 1])


s = input()
n = len(s)
dp = [0] * n
for i in range(n):
	if i > 0:
		dp[i] += dp[i - 1]
	if i < n - 1:
		dp[i] += int(s[i] == s[i + 1])
dp = [0] + dp
m = int(input())
results = []
for i in range(m):
	(l, r) = map(int, input().split())
	ans = dp[r - 1] - dp[l - 1]
	results.append(ans)
for result in results:
	print(result)


a = input()
import sys
b = [0]
x = 0
l = len(a)
for i in range(l - 1):
	if a[i] == a[i + 1]:
		x += 1
	b.append(x)
n = int(input())
for j in range(n):
	(x, y) = map(int, sys.stdin.readline().split())
	s = b[y - 1] - b[x - 1]
	sys.stdout.write(str(s) + '\n')


def query(s, n):
	a = []
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			a.append(1)
		else:
			a.append(0)
	st = [0]
	for i in range(1, n):
		st.append(st[-1] + a[i - 1])
	return st
s = input()
n = len(s)
dp = query(s, n)
m = int(input())
for _ in range(m):
	(l, r) = map(int, input().split())
	print(dp[r - 1] - dp[l - 1])


import sys
input = sys.stdin.readline

def main():
	s = input().strip()
	n = len(s)
	c = [0] + [int(s[i] == s[i + 1]) for i in range(n - 1)] + [0]
	p = [0] * (n + 1)
	p[1] = c[1]
	for i in range(1, n + 1):
		p[i] = c[i] + p[i - 1]
	for _ in range(int(input())):
		(l, r) = map(int, input().split())
		print(p[r - 1] - p[l - 1])
main()


from itertools import accumulate

def solve(str, m, queries):
	arr = map(lambda i: str[i] == str[i + 1], range(len(str) - 1))
	prefix = list(accumulate(arr))
	for i in range(m):
		print(prefix[queries[i][1] - 1] - prefix[queries[i][0] - 1])
str = 'x' + input()
m = int(input())
q = []
for i in range(m):
	q.append(list(map(int, input().split())))
solve(str, m, q)


s = input()
l = [0, 0]
q = 1
while q < len(s):
	if s[q - 1] == s[q]:
		l.append(l[-1] + 1)
	else:
		l.append(l[-1])
	q += 1
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	print(abs(l[x] - l[y]))


import sys

def prefix(A):
	if len(A) == 0:
		return []
	ret = [0]
	for i in range(0, len(A) - 1):
		x = 1 if A[i] == A[i + 1] else 0
		ret.append(x + ret[i])
	ret.append(0)
	return ret
s = sys.stdin.readline()
p = prefix(s)
n = int(sys.stdin.readline())
for i in range(n):
	(l, r) = map(int, sys.stdin.readline().split(' '))
	sys.stdout.write(str(p[r - 1] - p[l - 1]) + '\n')


s = input()
z = 0
b = [0]
for i in range(1, len(s)):
	if s[i - 1] == s[i]:
		z += 1
	b.append(z)
b.append(z)
q = int(input())
for t in range(q):
	(l, r) = map(int, input().split())
	print(b[r - 1] - b[l - 1])


s = input()
s0 = [0, 0]
n = int(input())
cou = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		cou += 1
	s0.append(cou)
for i in range(n):
	(a, b) = map(int, input().split())
	print(s0[b] - s0[a])


st = input()
n = len(st)
dp = [0 for i in range(n)]
for i in range(1, n):
	if st[i] == st[i - 1]:
		dp[i] = 1 + dp[i - 1]
	else:
		dp[i] = dp[i - 1]
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	print(dp[y - 1] - dp[x - 1])


s = input()
n = int(input())
a = [0] * len(s)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		a[i] = 1
	else:
		a[i] = 0
for i in range(1, len(s)):
	a[i] += a[i - 1]
for i in range(n):
	(x, y) = map(int, input().split())
	print(a[y - 1] - a[x - 1])


str = input()
m = int(input())
q = []
for i in range(m):
	p = []
	p = [int(x) for x in input().split()]
	q.append(p)
l = []
l.append(0)
c = 0
n = len(str)
for i in range(n - 1):
	if str[i] == str[i + 1]:
		c = c + 1
	l.append(c)
for i in range(m):
	a = q[i][0] - 1
	b = q[i][1] - 1
	print(l[b] - l[a])


from sys import stdin
s = input()
A = [0] * len(s)
if s[0] == s[1]:
	A[0] = 1
for i in range(1, len(s) - 1):
	if s[i] == s[i + 1]:
		A[i] = A[i - 1] + 1
	else:
		A[i] = A[i - 1]
A[-1] = A[-2] + 1
A = [0] + A
case = int(stdin.readline())
ans = ''
for c in range(0, case):
	(l, r) = [int(x) for x in stdin.readline().split()]
	ans += str(A[r - 1] - A[l - 1]) + '\n'
print(ans)


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
s = input()
cnt1 = [0] * (len(s) + 1)
cnt2 = [0] * (len(s) + 1)
for i in range(1, len(s)):
	if s[i] == '.' and s[i] == s[i - 1]:
		cnt1[i + 1] = cnt1[i] + 1
	else:
		cnt1[i + 1] = cnt1[i]
	if s[i] == '#' and s[i] == s[i - 1]:
		cnt2[i + 1] = cnt2[i] + 1
	else:
		cnt2[i + 1] = cnt2[i]
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ans = cnt1[y] + cnt2[y] - cnt1[x] - cnt2[x]
	print('%d\n' % ans)


from sys import stdin
s = stdin.readline().strip()
dp = [0 for i in range(len(s))]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		dp[i] = 1
dps = [dp[0]] + [0 for i in range(len(s) - 1)]
for i in range(1, len(s)):
	dps[i] = dps[i - 1] + dp[i]
for _ in range(int(stdin.readline())):
	(l, r) = map(int, stdin.readline().split())
	l -= 1
	r -= 2
	if l == 0:
		print(dps[r])
	else:
		print(dps[r] - dps[l - 1])


s = input()
m = int(input())
c = [0] * (len(s) + 1)
current = 0
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		current += 1
	c[i] = current
for _ in range(m):
	(l, r) = map(int, input().split())
	print(c[r - 1] - c[l - 1])


s = input().strip()
num_queries = int(input())
slen = len(s)

def create_lookup_table(s):
	length = len(s) - 1
	res = [1] if s[0] == s[1] else [0]
	for i in range(1, length):
		if s[i] == s[i + 1]:
			res.append(res[-1] + 1)
		else:
			res.append(res[-1])
	return res
sums = create_lookup_table(s)
res = []
for _ in range(num_queries):
	(l1, r1) = map(int, input().split())
	(l, r) = (l1 - 1, r1 - 1)
	query = sums[r - 1] - (sums[l - 1] if l > 0 else 0)
	res.append(query)
for r in res:
	print(r)


from sys import *
s = stdin.readline()
c = 0
l = [0]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		c = c + 1
	l.append(c)
for u in range(int(input())):
	(x, y) = map(int, stdin.readline().split())
	print(l[y - 1] - l[x - 1])


s = input()
array = [0] * 100001
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		array[i + 1] = array[i] + 1
	else:
		array[i + 1] = array[i]
m = int(input())
for i in range(m):
	(l, r) = input().split()
	print(array[int(r)] - array[int(l)])


import sys
input = sys.stdin.readline
s = input()
l = [0] * (len(s) + 1)
n = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		l[i] += 1
		if n == 0:
			n = i
for i in range(max(0, n - 2), len(s)):
	l[i] += l[i - 1]
for i in range(int(input())):
	(le, r) = map(int, input().split())
	print(l[r - 2] - l[le - 2])


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	s = S()
	l = len(s)
	n = I()
	t = [0] * l
	for i in range(l - 1):
		if s[i] == s[i + 1]:
			t[i] = 1
	w = [0]
	for i in range(l):
		w.append(w[-1] + t[i])
	r = []
	for _ in range(n):
		(a, b) = LI()
		r.append(w[b - 1] - w[a - 1])
	return '\n'.join(map(str, r))
print(main())


n = input()
_ = int(input())
a = [0]
cout = ''
for i in range(len(n) - 1):
	a += [a[-1] + (n[i] == n[i + 1])]
for i in range(_):
	(l, r) = map(int, input().split())
	cout += str(a[r - 1] - a[l - 1]) + '\n'
print(cout)


string = input()
dp = [0] * 100001
l = len(string)
for i in range(l - 1):
	if string[i] == string[i + 1]:
		dp[i + 2] = dp[i + 1] + 1
	else:
		dp[i + 2] = dp[i + 1]
ans = []
for k in range(int(input())):
	(m, n) = map(int, input().split())
	ans.append(dp[n] - dp[m])
for g in ans:
	print(g)


from collections import *
from sys import *

def input():
	return stdin.readline()

def finder2():
	s = input()
	l = []
	vis = defaultdict(lambda : False)
	for i in range(len(s) - 1):
		if s[i] == '#' and s[i + 1] == '.' or (s[i] == '.' and s[i + 1] == '#'):
			vis[i + 1] = True
	prefix = [0 for i in range(len(s) + 1)]
	for i in range(1, len(s) + 1):
		prefix[i] += prefix[i - 1]
		if vis[i]:
			prefix[i] += 1
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		print(y - x - (prefix[y - 1] - prefix[x - 1]))
finder2()


import sys, math, string
input = sys.stdin.readline
from collections import deque
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
l = input()
a = [0]
for i in range(1, len(l)):
	if l[i - 1] == l[i]:
		a.append(1 + a[-1])
	else:
		a.append(a[-1])
n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	sys.stdout.write(str(a[r - 1] - a[l - 1]) + '\n')


import sys
from sys import stdin, stdout
s = stdin.readline()
sumi = []
sumi.insert(-1, 0)
for i in range(0, len(s) - 1):
	if s[i] == s[i + 1]:
		sumi.insert(i, sumi[i - 1] + 1)
	else:
		sumi.insert(i, sumi[i - 1])
n = input()
for i in range(0, int(n)):
	(l, r) = stdin.readline().split()
	stdout.write('%s\n' % (sumi[int(r) - 2] - sumi[int(l) - 2]))


s = input()
m = int(input())
n = len(s)
a = [0] * n
same_count = 0
a[0] = 0
ans = ''
for i in range(0, n - 1):
	if s[i] == s[i + 1]:
		same_count += 1
		a[i + 1] = same_count
	else:
		a[i + 1] = same_count
for i in range(m):
	(l, s) = map(int, input().split())
	ans += str(a[s - 1] - a[l - 1]) + '\n'
print(ans)


s = input()
m = int(input())
calc = [0]
out = []
for i in range(1, len(s)):
	count = calc[i - 1]
	if s[i] == s[i - 1]:
		count += 1
	calc.append(count)
for q in range(m):
	L = [int(it) for it in input().split()]
	(l, r, count) = (L[0] - 1, L[1] - 1, 0)
	out.append(calc[r] - calc[l])
for c in out:
	print(c)


s = input()
n = len(s)
dict = {}
cnt = 0
dict[0] = 0
for i in range(n - 1):
	if s[i] == s[i + 1]:
		cnt += 1
	dict[i + 1] = cnt
	i += 1
dict[n] = cnt + 1
m = int(input())
s = ''
for i in range(m):
	(l, r) = map(int, input().split())
	s += str(dict[r - 1] - dict[l - 1])
	s += '\n'
print(s)


s = input()
n = len(s)
a = [0] * n
m = int(input())
for i in range(1, n):
	a[i] = a[i - 1] + (1 if s[i] == s[i - 1] else 0)
for _ in range(m):
	(l, r) = map(int, input().split())
	ans = a[r - 1] - a[l - 1]
	print(ans)


import itertools
a = 'x' + input()
b = list(itertools.accumulate(map(lambda i: a[i] == a[i + 1], range(len(a) - 1))))
m = int(input())
q = []
for x in range(m):
	q.append(list(map(int, input().split())))
for x in range(m):
	print(b[q[x][1] - 1] - b[q[x][0] - 1])


n = input()
nlen = len(n)
res = [0] * (nlen + 2)
for i in range(1, nlen):
	if n[i] == n[i - 1]:
		res[i + 1] = res[i] + 1
	else:
		res[i + 1] = res[i]
val = []
m = int(input())
for i in range(m):
	(x, y) = [int(i) for i in input().split()]
	val.append(res[y] - res[x])
for i in range(m):
	print(val[i])


s = input()
num = int(input())
res = []
ans = []
pairscount = 0
res.append(0)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		pairscount += 1
	res.append(pairscount)
for i in range(0, num):
	(x, y) = map(int, input().split())
	ans.append(res[y - 1] - res[x - 1])
for i in ans:
	print(i)


string_entrada = input()
vetor_1 = [0] * (len(string_entrada) + 1)
cont = 0
for i in range(1, len(string_entrada)):
	if string_entrada[i] == string_entrada[i - 1]:
		vetor_1[i] = 1
vetor_2 = vetor_1
for i in range(1, len(string_entrada)):
	vetor_2[i] = vetor_1[i] + vetor_2[i - 1]
n = int(input())
for i in range(n):
	(l, r) = input().split()
	print(vetor_2[int(r) - 1] - vetor_2[int(l) - 1])


from sys import stdin, stdout
input = stdin.readline
kik = input()[:-1]
nancy = len(kik)
arr = [0] * nancy
for i in range(1, nancy):
	if kik[i - 1] == kik[i]:
		arr[i] = arr[i - 1] + 1
	else:
		arr[i] = arr[i - 1]
for i in range(int(input())):
	(j, k) = map(int, input().split())
	stdout.write(str(arr[k - 1] - arr[j - 1]))
	stdout.write('\n')


s = input()
m = int(input())
dp = [0] * len(s)
for n in range(len(s) - 1):
	dp[n + 1] = dp[n] + (s[n + 1] == s[n])
ans = []
for _ in range(m):
	(l, r) = map(int, input().split())
	ans.append(dp[r - 1] - dp[l - 1])
print(*ans, sep='\n')


def main():
	op = ''
	ip = input()
	cum_sum = process(ip)
	t = int(input())
	for i in range(t):
		(l, r) = map(int, input().split(' '))
		op += str(cum_sum[r - 1] - cum_sum[l - 1]) + '\n'
	print(op)

def process(ip):
	prev = ip[0]
	cnt = 0
	op = []
	op.append(0)
	for i in range(1, len(ip)):
		if ip[i] == prev:
			cnt += 1
		prev = ip[i]
		op.append(cnt)
	return op
main()


s = input()
n = len(s)
q = int(input())
Q = []
for i in range(q):
	Q.append(list(map(int, input().split())))
Sum = n * [0]
for i in range(1, n):
	Sum[i] = Sum[i - 1]
	if s[i] == s[i - 1]:
		Sum[i] += 1
for i in range(q):
	print(Sum[Q[i][1] - 1] - Sum[Q[i][0] - 1])


s = 'g' + input()
le = len(s)
f = [0] * (le + 1)
for i in range(1, le - 1):
	f[i] = f[i - 1] + (s[i] == s[i + 1])
m = int(input())
while m > 0:
	m -= 1
	(l, r) = map(int, input().split())
	print(f[r - 1] - f[l - 1])


s = input()
m = int(input())
n = len(s)
dp = [0] * (n + 2)
pr = []
for i in range(1, n):
	if s[i] == s[i - 1]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
for i in range(m):
	o = input().split()
	l = int(o[0])
	r = int(o[1])
	p = dp[r - 1] - dp[l - 2]
	if s[l - 2] == s[l - 1] and l != 1:
		p -= 1
	pr += [str(p)]
print('\n'.join(pr))


import sys
dp = []

def build_rsq(s):
	a = 0
	dp.append(0)
	for x in range(len(s) - 1):
		if s[x] == s[x + 1]:
			a = a + 1
		dp.append(a)

def query_rsq(l, r):
	return dp[r - 1] - dp[l - 1]
s = sys.stdin.readline()
m = int(sys.stdin.readline())
build_rsq(s)
for _ in range(m):
	(l, r) = [int(x) for x in sys.stdin.readline().split()]
	print(query_rsq(l, r))


s = input()
m = int(input())
sm = [0] * len(s)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		sm[i] = sm[i - 1] + 1
	else:
		sm[i] = sm[i - 1]
ls = []
rs = []
for _ in range(m):
	(l, r) = map(int, input().split())
	ls.append(l)
	rs.append(r)
for i in range(m):
	print(sm[rs[i] - 1] - sm[ls[i] - 1])


s = input()
a = (len(s) - 1) * [0]
cur_cnt = 0
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		cur_cnt += 1
	a[i - 1] = cur_cnt
m = int(input())
ans = []
for j in range(m):
	(l, r) = map(int, input().split())
	if l == 1:
		ans.append(a[r - 2])
	else:
		ans.append(a[r - 2] - a[l - 2])
print(*ans, sep='\n')


s = str(input())
num = int(input())
a = []
a.append(0)
pair = 0
pr = []
for i in range(1, len(s)):
	if s[i - 1] == s[i]:
		pair += 1
	a.append(pair)
for j in range(num):
	(f, e) = [int(x) for x in input().split()]
	pr.append(str(a[e - 1] - a[f - 1]))
print('\n'.join(pr))


s = input()
n = int(input())
m = len(s)
dp = [0] * (m + 1)
for i in range(1, m + 1):
	dp[i] = dp[i - 1]
	if i != 1 and s[i - 1] == s[i - 2]:
		dp[i] += 1
ans = ''
for i in range(n):
	(l, r) = map(int, input().split())
	ans += str(dp[r] - dp[l]) + '\n'
print(ans, end='')


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
s = cin()[:-1]
(m,) = mp()
l = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		l += [l[-1] + 1]
	else:
		l += [l[-1]]
for i in range(m):
	(p, r) = mp()
	cout(str(l[r - 1] - l[p - 1]) + '\n')


st = input()
queries = int(input())
cnt = 1
lis = []
lis.append(cnt)
for i in range(1, len(st)):
	if st[i] == st[i - 1]:
		cnt += 1
	lis.append(cnt)
while queries > 0:
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	print(lis[r] - lis[l])
	queries -= 1


(Sentence, Result) = (input(), '')
LenSentence = len(Sentence)
Check = [0] * LenSentence
for index in range(LenSentence - 1):
	Check[index + 1] = Check[index] + (Sentence[index] == Sentence[index + 1])
for i in range(int(input())):
	X = list(map(int, input().split()))
	Result += str(Check[X[1] - 1] - Check[X[0] - 1]) + '\n'
print(Result)


a = input('')
n = int(input(''))
b = [0]
c = []
count = 0
for i in range(1, len(a)):
	if a[i] is a[i - 1]:
		count += 1
		b.append(count)
	elif a[i] is not a[i - 1]:
		b.append(count)
for _ in range(n):
	a = [int(x) for x in input().split()]
	v = b[a[1] - 1] - b[a[0] - 1]
	c.append(v)
for elements in c:
	print(elements)


import sys
input = sys.stdin.readline
s = input()
n = len(s)
X = [0 for i in range(n)]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		X[i] = 1
DP = [0]
t = 0
for i in X:
	t = t + i
	DP.append(t)
m = int(input())
for i in range(m):
	(L, R) = map(int, input().split())
	x = DP[R - 1] - DP[L - 1]
	print(x)


s = input()
t = int(input())
l = [0]
ma = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		l.append(l[-1] + 1)
	else:
		l.append(l[-1])
for _ in range(t):
	(i, j) = list(map(int, input().split()))
	print(l[j - 1] - l[i - 1])


s = input()
a = [0] * len(s)
for i in range(1, len(s)):
	a[i] = a[i - 1] + (1 if s[i] == s[i - 1] else 0)
n = int(input())
t = ''
for i in range(0, n):
	[l, r] = list(map(int, input().split(' ')))
	t += str(a[r - 1] - a[l - 1]) + '\n'
print(t)


l = list(input())
d = 0
r = [0]
for k in range(1, len(l)):
	if l[k] == l[k - 1]:
		d += 1
	r.append(d)
for q in range(int(input())):
	(m, n) = map(int, input().split())
	print(r[n - 1] - r[m - 1])


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
s = input()
n = ii()
d = [0]
for i in range(1, len(s)):
	d.append(d[-1] + (s[i] == s[i - 1]))
res = []
for _ in range(n):
	(l, r) = mi()
	res.append(d[r - 1] - d[l - 1])
prr(res, '\n')


import sys
s = str(sys.stdin.readline())
m = int(sys.stdin.readline())
o = 0
dp = [0]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		o += 1
	dp.append(o)
ans = []
for _ in range(m):
	(i, j) = map(int, sys.stdin.readline().split())
	ans.append(dp[j - 1] - dp[i - 1])
sys.stdout.write('\n'.join(map(str, ans)))


from sys import stdin
s = input()
t = int(input())
l = len(s)
d = [0] * l
for i in range(l - 1):
	d[i + 1] = d[i]
	if s[i] == s[i + 1]:
		d[i + 1] += 1
for _ in range(t):
	(li, ri) = map(int, stdin.readline().split())
	li -= 1
	ri -= 1
	print(d[ri] - d[li])


def str2dic(s):
	dic = dict()
	i = 0
	while i + 1 < len(s):
		if s[i] == s[i + 1]:
			dic[i] = 1
		else:
			dic[i] = 0
		i += 1
	return dic

def get_sum(d0):
	d1 = dict()
	d1[0] = d0[0]
	for i in range(1, len(d0)):
		d1[i] = d1[i - 1] + d0[i]
	return d1

def str2pair(s):
	l = s.split()
	t = tuple()
	for i in l:
		t = t + (int(i),)
	return t

def get_input():
	global oris
	global n
	global pair
	oris = input()
	tmp = input()
	n = int(tmp)
	i = 0
	while i < n:
		tmp = input()
		pair.append(str2pair(tmp))
		i += 1
	return None
oris = ''
n = 0
pair = []
get_input()
dic = str2dic(oris)
sum = get_sum(dic)
for (l, r) in pair:
	if l == 1:
		ans = sum[r - 2]
	else:
		ans = sum[r - 2] - sum[l - 2]
	print(ans)


def take_input(s):
	if s == 1:
		return int(input())
	return map(int, input().split())
s = input()
till = [0]
curr = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		curr += 1
	till.append(curr)
n = take_input(1)
for i in range(n):
	(l, r) = take_input(2)
	print(till[r - 1] - till[l - 1])


from collections import defaultdict

def help_ilya(queries, s):
	n = len(s)
	dpt = defaultdict(int)
	A = [1 if s[i] == s[i + 1] else 0 for i in range(n - 1)]
	Sum = []
	Sum.append(A[0])
	for i in range(1, n - 1):
		Sum.append(Sum[i - 1] + A[i])
	for query in queries:
		(l, r) = query
		if l != 0:
			print(Sum[r - 1] - Sum[l - 1])
		else:
			print(Sum[r - 1] - 0)
s = input()
m = int(input())
queries = []
for _ in range(m):
	(l, r) = [int(i) for i in input().split()]
	queries.append((l - 1, r - 1))
help_ilya(queries, s)


s = input()
y = len(s)
lists = [0]
x = 0
for i in range(1, y):
	if s[i - 1] == s[i]:
		lists.append(lists[i - 1] + 1)
	else:
		lists.append(lists[i - 1])
m = int(input())
listl = []
listr = []
for j in range(m):
	(l, r) = map(int, input().split())
	listl.append(l)
	listr.append(r)
for k in range(m):
	numl = listl[k] - 1
	numr = listr[k] - 1
	print(lists[numr] - lists[numl])


n = input()
m = int(input())
s = [0] * (len(n) + 1)
for i in range(len(n) - 1):
	if n[i + 1] == n[i]:
		s[i + 1] = s[i] + 1
	else:
		s[i + 1] = s[i]
result = []
for y in range(m):
	(l, r) = list(map(int, input().split()))
	result.append(s[r - 1] - s[l - 1])
for i in result:
	print(i)


import sys
input = sys.stdin.readline
s = input()
n = len(s)
m = int(input())
dp = [0] * n
for i in range(1, n):
	if s[i] == s[i - 1]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
for i in range(m):
	(l, r) = list(map(int, input().split()))
	print(dp[r - 1] - dp[l - 1])


s = input()
l = []
n = len(s) - 1
for i in range(n):
	k = 1 if s[i] == s[i + 1] else 0
	l.append(k)
dp = [0]
for i in range(n):
	dp.append(dp[-1] + l[i])
output = []
for i in range(int(input())):
	(a, b) = map(int, input().split())
	output.append(str(dp[b - 1] - dp[a - 1]))
print('\n'.join(output))


z = input()
v = int(input())
CS = [0]
for i in range(len(z) - 1):
	if z[i + 1] == z[i]:
		CS.append(CS[-1] + 1)
	else:
		CS.append(CS[-1])
answ = []
for i in range(v):
	(l, r) = map(int, input().split())
	answ.append(CS[r - 1] - CS[l - 1])
for i in answ:
	print(i)


n = input()
a = [0] * len(n)
k = 0
for i in range(1, len(n)):
	if n[i - 1] == n[i]:
		k += 1
	a[i] = k
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	print(a[m - 1] - a[n - 1])


msg = input()
a = [0] * 1000001
a[1] = 0
for i in range(1, len(msg)):
	if msg[i] == msg[i - 1]:
		a[i + 1] = a[i] + 1
	else:
		a[i + 1] = a[i]
m = int(input())
for i in range(0, m):
	(l, r) = map(int, input().split())
	print(a[r] - a[l])


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
dgl = lambda : list(map(int, input()))
il = lambda : list(map(int, input().split()))
s = si()
t = ii()
l = [0]
q = []
n = len(s)
for _ in range(t):
	q.append(il())
for i in range(n - 1):
	if s[i] == s[i + 1]:
		l.append(l[-1] + 1)
	else:
		l.append(l[-1] + 0)
for i in q:
	print(l[i[1] - 1] - l[i[0] - 1])


s = input()
a = [0]
x = 0
for i in range(len(s) - 1):
	x += 1 if s[i] == s[i + 1] else 0
	a.append(x)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	print(a[m - 1] - a[n - 1])


import sys
input = sys.stdin.readline
s = input()
dp = [0]
for i in range(len(s) - 1):
	if s[i + 1] == s[i]:
		dp.append(dp[-1] + 1)
	else:
		dp.append(dp[-1])
n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	print(dp[y - 1] - dp[x - 1])


def ilya_and_queries(a, f, n):
	d = [0] * len(s)
	for i in range(1, len(s)):
		d[i] = d[i - 1]
		if a[i] == a[i - 1]:
			d[i] += 1
	ans = []
	for i in range(n):
		(l, r) = f[i]
		ans.append(d[r - 1] - d[l - 1])
	for i in range(n):
		print(ans[i])
s = input()
m = int(input())
v = []
for i in range(m):
	(x, y) = list(map(int, input().split()))
	v.append([x, y])
ilya_and_queries(s, v, m)


seq = list(input())
num = int(input())
res = []
hold = 0
c = 0
ans = []
for i in range(0, len(seq)):
	if i == 0:
		res.append(0)
		continue
	res.append(res[i - 1])
	if seq[i] == seq[i - 1]:
		res[i] += 1
while c < num:
	(x, y) = map(int, input().split())
	ans.append(res[y - 1] - res[x - 1])
	c += 1
for i in ans:
	print(i)


l = input()
n = len(l)
arr = [0] * n
for i in range(1, n):
	if l[i] == l[i - 1]:
		arr[i] = arr[i - 1] + 1
	else:
		arr[i] = arr[i - 1]
if l[-2] == l[-1]:
	arr[-1] = arr[-2] + 1
else:
	arr[-1] = arr[-2]
ans = ''
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ans += str(arr[y - 1] - arr[x - 1]) + '\n'
print(ans)


s = input()
n = int(input())
le = len(s)
arr = [0] * (le + 1)
for i in range(1, le):
	if s[i] == s[i - 1]:
		arr[i] = 1
		arr[i] = arr[i - 1] + 1
	else:
		arr[i] = arr[i - 1]
arr[-1] = arr[-2]
for i in range(n):
	(l, r) = map(int, input().split())
	print(arr[r - 1] - arr[l - 1])


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
s = input()
n = len(s)
q = int(input())
ans = [0 for i in range(n)]
for i in range(1, n):
	if s[i] == s[i - 1]:
		ans[i] = ans[i - 1] + 1
	else:
		ans[i] = ans[i - 1]
for _ in range(q):
	(l, r) = map(int, input().split())
	l = l - 1
	r = r - 1
	print(ans[r] - ans[l])


n = input()
m = int(input())
list_n = [0] * len(n)
for x in range(len(n) - 1):
	list_n[x + 1] = list_n[x] + (n[x] == n[x + 1])
out = ''
for x in range(m):
	(l, r) = map(int, input().split())
	out += str(list_n[r - 1] - list_n[l - 1]) + '\n'
print(out[:-1])


def main():
	from sys import stdin, stdout
	s = stdin.readline().strip()
	flag = s[0]
	if flag == '.':
		anti = '#'
	else:
		anti = '.'
	n = len(s)
	l = [0 for x in range(n)]
	for i in range(1, n):
		if s[i] == flag:
			l[i] = l[i - 1] + 1
		else:
			(flag, anti) = (anti, flag)
			l[i] = l[i - 1]
	for _ in range(int(stdin.readline())):
		(a, b) = map(int, stdin.readline().split())
		stdout.write(str(l[b - 1] - l[a - 1]) + '\n')
main()


l = [0]
j = ''
for i in input():
	l.append(l[-1])
	l[-1] += [0, 1][i == j]
	j = i
for i in range(int(input())):
	(lf, r) = map(int, input().split())
	print(l[r] - l[lf])


s1 = input()
t = int(input())
l1 = [0]
s = 0
for i in range(1, len(s1)):
	if s1[i] == s1[i - 1]:
		s = s + 1
		l1.append(s)
	else:
		l1.append(s)
l = []
for j in range(t):
	x = input().split()
	x = list(map(int, x))
	l.append(x)
for k in l:
	print(l1[k[1] - 1] - l1[k[0] - 1])


s = input()
n = int(input())
ans = []
dp = [0] * len(s)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
for i in range(n):
	(p, e) = map(int, input().split(' '))
	ans.append(dp[e - 1] - dp[p - 1])
print(*ans, sep='\n')


s = input()
m = int(input())
n = len(s)
a = []
for i in range(m):
	a.append(tuple(map(int, input().split())))
dp = [0] * n
for i in range(1, n):
	if s[i] == s[i - 1]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
for i in a:
	print(dp[i[1] - 1] - dp[i[0] - 1])


a = input()
b = len(a)
k = [0] * b
m = ''
for i in range(b - 1):
	if a[i] == a[i + 1]:
		c = 1
	else:
		c = 0
	k[i + 1] = k[i] + c
for i in range(int(input())):
	(d, e) = list(map(int, input().split()))
	m += str(k[e - 1] - k[d - 1]) + '\n'
print(m)


from sys import stdin, stdout

def main():
	s = input()
	check = [0] * (len(s) + 1)
	dp = [0] * (len(s) + 1)
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			check[i + 1] = 1
	for i in range(2, len(s) + 1):
		dp[i] += dp[i - 1] + check[i]
	m = int(stdin.readline())
	for _ in range(m):
		(x, y) = map(int, stdin.readline().split())
		if x == y:
			stdout.write('0')
		else:
			stdout.write(str(dp[y] - dp[x]))
		stdout.write('\n')
main()


i1 = str(input())
i2 = int(input())
scores = []
scores.append(0)
consecutive = 0
i3 = []
for i in range(0, i2):
	i3.append([int(x) for x in input().split()])
for i in range(0, len(i1) - 1):
	if i1[i] == i1[i + 1]:
		consecutive += 1
	scores.append(consecutive)
for i in range(0, i2):
	print(scores[i3[i][1] - 1] - scores[i3[i][0] - 1])


s = input()
n = int(input())
a = [0]
x = 0
out = ''
for i in range(len(s) - 1):
	x += 1 if s[i] == s[i + 1] else 0
	a.append(x)
for i in range(n):
	(l, r) = map(int, input().split())
	out += str(a[r - 1] - a[l - 1]) + '\n'
print(out)


from sys import stdin
string = stdin.readline()[:-1]
cum = [0] * (len(string) + 1)
idx = len(string) - 2
while idx >= 0:
	cum[idx + 1] = cum[idx + 2] + (string[idx] == string[idx + 1])
	idx -= 1
cnt = int(stdin.readline())
for q in range(cnt):
	line = stdin.readline().split()
	(st, end) = (int(line[0]), int(line[1]))
	print(cum[st] - cum[end])


import sys
input = sys.stdin.readline
s = input()
l = [0]
c = 0
for i in range(0, len(s) - 1):
	if s[i] == s[i + 1]:
		c += 1
	l.append(c)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(l[b - 1] - l[a - 1])


s = input()
m = len(s)
n = int(input())
memo = [0 for _ in s]
for i in range(1, m):
	if s[i] == s[i - 1]:
		memo[i] = memo[i - 1] + 1
	else:
		memo[i] = memo[i - 1]
for i in range(n):
	(l, r) = input().split()
	l = int(l) - 1
	r = int(r) - 1
	print(memo[r] - memo[l])


s = input()
m = int(input())
q = [[]] * m
for i in range(m):
	q[i] = list(map(int, input().split()))
a = [0] * (len(s) + 1)
acc = 0
for i in range(len(s)):
	if i + 1 < len(s) and s[i] == s[i + 1]:
		acc += 1
	a[i + 1] = acc
for (l, r) in q:
	print(a[r - 1] - a[l - 1])


def convert(ch):
	return 1 if ch == '.' else -1

def main():
	s = input()
	acc = [0 for i in range(0, len(s) + 1)]
	idx = 2
	for nm in range(1, len(s)):
		acc[idx] = abs(convert(s[nm]) + convert(s[nm - 1])) / 2 + acc[idx - 1]
		idx += 1
	q = int(input())
	o = ''
	for i in range(0, q):
		qI = [int(e) for e in input().split()]
		o += str(int(acc[qI[1]] - acc[qI[0]])) + '\n'
	print(o)
	return 0
main()


s = input()
a = [0] * len(s)
cnt = 0
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		cnt += 1
	a[i] = cnt
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	print(a[r - 1] - a[l - 1])


line = input()
n = int(input())
queries = []
pairs = [0]
count = 0
for i in range(n):
	queries.append([int(i) for i in input().split()])
for i in range(len(line) - 1):
	if line[i] == line[i + 1]:
		count += 1
	pairs.append(count)
for query in queries:
	print(pairs[query[1] - 1] - pairs[query[0] - 1])


def main():
	l = list(input())
	m = [0]
	n = len(l)
	z = int(input())
	for i in range(n - 1):
		m.append(1 if l[i] == l[i + 1] else 0)
	l1 = [0]
	for i in range(1, n):
		l1.append(l1[-1] + m[i])
	l2 = [list(map(int, input().split())) for i in range(z)]
	for (u, v) in l2:
		(u, v) = (u - 1, v - 1)
		if u == 0:
			print(l1[v])
		else:
			print(l1[v] - l1[u])
main()


from sys import stdin
s = stdin.readline().rstrip()
n = int(stdin.readline().rstrip())
l = []
t = 0
l.append(0)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		t += 1
	l.append(t)
while n > 0:
	c = 0
	(a, b) = map(int, stdin.readline().split())
	print(l[b - 1] - l[a - 1])
	n -= 1


line = input()
m = int(input())
queries = []
for i in range(m):
	lst = [int(i) for i in input().split()]
	queries.append((lst[0], lst[1]))
lst = [0, 0]
for i in range(1, len(line)):
	if line[i - 1] == line[i]:
		lst.append(lst[i] + 1)
	else:
		lst.append(lst[i])
for query in queries:
	(first, second) = query
	print(lst[second] - lst[first])


s = input()
n = len(s)
dp = [0] * n
for i in range(1, n):
	dp[i] = dp[i - 1] + (s[i] == s[i - 1])
m = int(input())
output = []
for j in range(m):
	(a, b) = map(int, input().split())
	output.append(dp[b - 1] - dp[a - 1])
print('\n'.join(map(str, output)))


s = input()
n = len(s)
p = [0]
i = 1
while i < n:
	if s[i] == s[i - 1]:
		p.append(p[-1] + 1)
	else:
		p.append(p[-1])
	i += 1
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	print(p[r] - p[l])


s = input()
possible = []
(prev, k) = ('s', 1)
for i in s:
	if i == prev:
		k += 1
	possible.append(k)
	prev = i
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	print(possible[r - 1] - possible[l - 1])


st = input()
el = int(input())
res = [0] * len(st)
for x in range(1, len(st)):
	res[x] = res[x - 1] + (st[x] == st[x - 1])
for x in range(el):
	ar = []
	for y in input().split(' '):
		ar.append(int(y))
	print(res[ar[1] - 1] - res[ar[0] - 1])


from collections import defaultdict
import bisect
from itertools import accumulate, count
import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
s = input()
ans = [0]
z = 0
for i in range(0, len(s)):
	ans.append(ans[-1] + (1 if z == s[i] else 0))
	z = s[i]
for i in range(int(input())):
	(x, y) = map(int, input().split())
	print(ans[y] - ans[x])


s = input()
m = int(input())
o = 0
dp = [0]
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		o += 1
	dp.append(o)
ans = []
for _ in range(m):
	(i, j) = map(int, input().split())
	ans.append(dp[j - 1] - dp[i - 1])
print('\n'.join(map(str, ans)))


a = input()
n = int(input())
ans = ''
b = [0 for i in range(len(a))]
r = 0
for i in range(len(a) - 1):
	if a[i] == a[i + 1]:
		r += 1
	b[i + 1] = r
for i in range(n):
	(l, r) = map(int, input().split())
	s = 0
	s = b[r - 1] - b[l - 1]
	ans += str(s)
	if i < n:
		ans += '\n'
print(ans)


s = list(input())
m = int(input())
cs = [0] * len(s)
for i in range(len(s) - 1):
	cs[i + 1] = cs[i]
	if s[i] == s[i + 1]:
		cs[i + 1] += 1
for i in range(m):
	(l, r) = map(int, input().split())
	print(cs[r - 1] - cs[l - 1])


from sys import stdin, stdout
s = stdin.readline()
m = int(stdin.readline())
counts = [0]
count = 0
for j in range(len(s) - 1):
	if s[j] == s[j + 1]:
		count += 1
	counts.append(count)
for i in range(m):
	count = 0
	(l, r) = map(int, stdin.readline().split(' '))
	stdout.write(str(counts[r - 1] - counts[l - 1]) + '\n')


t = 1
while t > 0:
	t -= 1
	s = input()
	n = len(s)
	l = list(s)
	dp = [0] * (n + 2)
	cnt = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			cnt += 1
		dp[i] = cnt
	m = int(input())
	for i in range(m):
		(s, r) = map(int, input().split())
		print(dp[r - 1] - dp[s - 1])


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase

def main():
	l = list(input())
	dp = [0]
	n = len(l)
	for x in range(1, n):
		if l[x] == l[x - 1]:
			dp.append(dp[-1] + 1)
		else:
			dp.append(dp[-1])
	for q in range(int(input())):
		(a, b) = map(int, input().split())
		print(dp[b - 1] - dp[a - 1])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
coso = stdin.readline()
acumulador = []
acumulador.append(0)
for i in range(1, len(coso) - 1):
	if coso[i - 1] == coso[i]:
		acumulador.append(acumulador[i - 1] + 1)
	else:
		acumulador.append(acumulador[i - 1])
cant = stdin.readline()
for querie in stdin:
	querie = querie.strip().split()
	res = acumulador[int(querie[1]) - 1] - acumulador[int(querie[0]) - 1]
	stdout.write(str(res) + '\n')


s = input()
arr = [0]
x = 0
prefix = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		x += 1
	prefix.append(x)
m = int(input())
ans = []
for i in range(m):
	(l, r) = map(int, input().split())
	ans.append(prefix[r - 1] - prefix[l - 1])
for i in ans:
	print(i)


def main():
	s = input()
	acc = [0]
	for i in range(1, len(s)):
		acc.append(acc[-1] + 1 if s[i] == s[i - 1] else acc[-1])
	t = int(input())
	queries = [[int(c) for c in input().split()] for _ in range(t)]
	res = []
	for (l, r) in queries:
		res.append(str(acc[r - 1] - acc[l - 1]))
	print('\n'.join(res))
main()


s = input()
length = len(s)
count = [0] * length
answer = ''
for i in range(length - 1):
	count[i + 1] = count[i]
	if s[i] == s[i + 1]:
		count[i + 1] += 1
for i in range(int(input())):
	(l, r) = map(int, input().split())
	answer += str(count[r - 1] - count[l - 1]) + '\n'
print(answer)


t = 1
for qwe in range(t):
	s = input()
	m = int(input())
	listtans = [0]
	if s[0] == s[1]:
		listtans.append(1)
	else:
		listtans.append(0)
	for i in range(1, len(s) - 1):
		temp = 0
		if s[i] == s[i + 1]:
			temp = 1
		listtans.append(listtans[-1] + temp)
	listtans.append(listtans[-1])
	for i in range(m):
		(l, r) = map(int, input().split())
		print(listtans[r - 1] - listtans[l - 1])


import sys
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, input().split()))
a = str(input())
ans = [0]
for i in range(1, len(a)):
	if a[i] == a[i - 1]:
		ans.append(ans[-1] + 1)
	else:
		ans.append(ans[-1])
for _ in range(int(input())):
	(b, c) = inp()
	print(ans[c - 1] - ans[b - 1])


s = input()
n = int(input())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
ans = 0
dp = [0] * len(s)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = dp[i - 1]
for (x, y) in arr:
	print(dp[y - 1] - dp[x - 1])


s = input()
b = [0] * len(s)
for i in range(len(s) - 1):
	b[i + 1] = b[i]
	if s[i] == s[i + 1]:
		b[i + 1] += 1
ans = ''
nq = int(input())
for i in range(nq):
	(l, h) = map(int, input().split())
	ans += str(b[h - 1] - b[l - 1]) + '\n'
print(ans)


s = list(input())
n = int(input())
q = [0] * n
m = [0] * (len(s) - 1)
a = 0
for i in range(n):
	b = input().split(' ')
	q[i] = (int(b[0]) - 1, int(b[1]) - 1)
for i in range(len(m)):
	if s[i] == s[i + 1]:
		a += 1
		m[i] = m[i - 1] + 1
	else:
		m[i] = m[i - 1]
for v in q:
	d = v[0] - 1
	if v[0] - 1 < 0:
		print(a - (a - m[v[1] - 1]))
	else:
		print(a - m[d] - (a - m[v[1] - 1]))


word = input()
l = len(word)
dp = [0] * l
for i in range(1, l):
	dp[i] = dp[i - 1] + (word[i] == word[i - 1])
query = int(input())
fuck = ''
for _ in range(query):
	(x, y) = map(int, input().split())
	fuck += str(dp[y - 1] - dp[x - 1]) + '\n'
print(fuck)


L = list(input())
n = int(input())
x = [0] * len(L)
op = ''
for i in range(len(L) - 1):
	x[i + 1] = x[i] + (L[i] == L[i + 1])
for i in range(n):
	(a, b) = map(int, input().split())
	op += str(x[b - 1] - x[a - 1]) + '\n'
print(op)


a = [i for i in input().strip()]
n = int(input())
lena = len(a)
ans = ''
test = [0] * lena
for i in range(lena - 1):
	test[i + 1] = test[i] + (a[i] == a[i + 1])
for i in range(n):
	(l, h) = map(int, input().split(' '))
	ans += str(test[h - 1] - test[l - 1]) + '\n'
print(ans)


string = input()
acumulado = [0] * (len(string) + 5)
somatorio = 0
for i in range(len(string) - 1):
	if string[i] == string[i + 1]:
		somatorio += 1
	acumulado[i + 1] = somatorio
ans = []
n = int(input())
for i in range(n):
	(inicio, fim) = map(int, input().split())
	ans.append(acumulado[fim - 1] - acumulado[inicio - 1])
for i in ans:
	print(i)


s = input()
m = int(input())
queries = []
for k in range(m):
	queries.append(tuple(map(int, input().split())))
table = [0]
for k in range(1, len(s)):
	if s[k] != s[k - 1]:
		table.append(table[-1] + 1)
	else:
		table.append(table[-1])
for k in queries:
	(a, b) = (k[0], k[1])
	print(b - a - (table[b - 1] - table[a - 1]))


from sys import stdout, stdin

def build_rsq():
	DP[0] = 0
	for I in range(1, n - 1):
		DP[I] = DP[I - 1]
		if string[I - 1] == string[I]:
			DP[I] += 1
	DP[n - 1] = DP[n - 2]

def rsq(l, r):
	return DP[r - 1] - DP[l - 1]
string = stdin.readline().strip()
n = len(string) + 1
DP = [0] * n
build_rsq()
queries = int(stdin.readline().strip())
for _ in range(queries):
	(l, r) = [int(n) for n in stdin.readline().strip().split()]
	stdout.write(str(rsq(l, r)) + '\n')


string = str(input())
n = len(string)
dp = [0] * (n + 1)
for i in range(n - 1):
	if string[i] == string[i + 1]:
		dp[i + 1] = dp[i] + 1
	else:
		dp[i + 1] = dp[i]
m = int(input())
for _ in range(m):
	(l, r) = map(int, input().split())
	print(dp[r - 1] - dp[l - 1])


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7
from bisect import bisect_left

def solve():
	S = getStr()
	Q = getInt()
	pref = [0]
	for j in range(len(S) - 1):
		if S[j] == S[j + 1]:
			pref.append(pref[-1] + 1)
		else:
			pref.append(pref[-1])
	for q in range(Q):
		(L, R) = getInts()
		print(pref[R - 1] - pref[L - 1])
	return
solve()


from sys import stdin, stdout
A = str(stdin.readline().split()[0])
DP = (len(A) + 1) * [0]

def build_rsq(n):
	for i in range(1, n - 1):
		DP[i] = DP[i - 1]
		if A[i] == A[i - 1]:
			DP[i] = DP[i] + 1
	DP[n - 1] = DP[n - 2]

def rsq(l, r):
	return int(DP[r] - DP[l])
build_rsq(len(A) + 1)
numbers_cases = int(stdin.readline())
for i in range(0, numbers_cases):
	query = list(stdin.readline().strip().split(' '))
	stdout.write(str(rsq(int(query[0]) - 1, int(query[1]) - 1)) + '\n')


string = input()
Length = len(string)
arr = [0] * Length
queries = int(input())
amount = 0
for char in range(1, Length):
	if string[char] == string[char - 1]:
		amount += 1
	arr[char] = amount
Dict = {}
for query in range(queries):
	Dict[query] = [int(a) for a in input().split()]
for query in range(queries):
	print(arr[Dict[query][1] - 1] - arr[Dict[query][0] - 1])


def proB(s, q):
	lst = [0] * len(s)
	ans = [0] * len(s)
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			lst[i] = 1
	ans[-1] = lst[-1]
	for i in range(len(lst) - 2, -1, -1):
		ans[i] = ans[i + 1] + lst[i]
	for i in q:
		(x, y) = i
		x -= 1
		y -= 1
		print(ans[x] - ans[y])
s = input()
t = int(input())
arr = []
for i in range(t):
	q = list(map(int, input().split()))
	arr.append(q)
proB(s, arr)


str = input()
querrys = int(input())
lis = []
cont = 0
for i in range(0, len(str) - 1):
	if str[i] == str[i + 1]:
		cont += 1
	lis.append(cont)
lis.insert(0, 0)
for i in range(querrys):
	q = input().split()
	l = int(q[0])
	r = int(q[1])
	print(lis[r - 1] - lis[l - 1])


s = input()
out = 0
dp = [0]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		out += 1
	dp.append(out)
m = int(input())
for i in range(m):
	(left, right) = map(int, input().split())
	print(dp[right - 1] - dp[left - 1])


s = input()
m = int(input())
l = len(s)
lefty_list = []
lefty_list.append(0)
i = 0
previous_element = ''
for elem in s:
	if elem == previous_element:
		i += 1
	lefty_list.append(i)
	previous_element = elem
i = 0
while i < m:
	(a, b) = map(int, input().split())
	i += 1
	print(lefty_list[b] - lefty_list[a])


from sys import stdin, stdout
DP = []

def build_rsq(a):
	for i in range(1, len(line)):
		if a[i] == a[i - 1]:
			DP[i + 1] = DP[i] + 1
		else:
			DP[i + 1] = DP[i]
for line in stdin:
	if line == '' or line == '\n':
		break
	line = [1 if x == '.' else 0 for x in list(line.strip())]
	DP = [0] * (len(line) + 1)
	build_rsq(line)
	qq = int(stdin.readline())
	for i in range(qq):
		qRange = [int(x) for x in stdin.readline().strip().split(' ')]
		stdout.write(str(DP[qRange[1]] - DP[qRange[0]]) + '\n')


import sys
input = sys.stdin.readline
s = input()
l = [0] * (10 ** 5 + 2)
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		l[i + 1] = l[i] + 1
	else:
		l[i + 1] = l[i]
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	print(l[m - 1] - l[n - 1])


v = input()
n = int(input())
(q, s) = ([], [0 for i in range(-1, len(v))])
sol = ''
for i in range(1, len(v)):
	s[i] = s[i - 1]
	if v[i] == v[i - 1]:
		s[i] += 1
for i in range(0, n):
	x = tuple(map(int, input().split()))
	sol += str(s[x[1] - 1] - s[x[0] - 1]) + '\n'
print(sol)


import sys
s = input().strip()
sl = [0]
nb = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		nb += 1
	sl.append(nb)
m = int(input())
for _ in range(m):
	(l, r) = map(int, sys.stdin.readline().split())
	print(sl[r - 1] - sl[l - 1])


s = input()
m = len(s)
bucket = [0] * m
for i in range(m - 1):
	if s[i] == s[i + 1]:
		bucket[i] = 1
for i in range(1, m):
	bucket[i] += bucket[i - 1]
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	if l == 0:
		print(bucket[r - 1])
	else:
		print(bucket[r - 1] - bucket[l - 1])


s = input().strip()
num_queries = int(input())
slen = len(s)
is_consecutives = [0 for i in range(slen)]
for i in range(slen):
	is_consecutives[i] = 1 if i < slen - 1 and s[i] == s[i + 1] else 0
sums = [0 for i in range(slen)]
curr_sum = 0
for i in range(slen):
	curr_sum += is_consecutives[i]
	sums[i] = curr_sum
res = []
for _ in range(num_queries):
	(l1, r1) = map(int, input().split())
	(l, r) = (l1 - 1, r1 - 1)
	query = sums[r - 1] - (sums[l - 1] if l > 0 else 0)
	res.append(query)
for r in res:
	print(r)


from sys import stdin, stdout
vector = stdin.readline().strip()
aux_vector = [-1] * len(vector)
cases = int(stdin.readline().strip())
tope = 0
aux_vector[0] = 0
for i in range(cases):
	par = stdin.readline().strip().split()
	a = int(par[0]) - 1
	b = int(par[1]) - 1
	if aux_vector[b] == -1:
		cont = aux_vector[tope]
		for j in range(tope, b):
			if vector[j] == vector[j + 1]:
				cont += 1
			aux_vector[j + 1] = cont
		tope = b
	stdout.write(str(aux_vector[b] - aux_vector[a]) + '\n')


s = input()
n = int(input())
result = [0]
score = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		score += 1
	else:
		score += 0
	result.append(score)
for i in range(n):
	(a, b) = [int(i) for i in input().split(' ')]
	print(result[b - 1] - result[a - 1])


def sol():
	s = input()
	m = int(input())
	dp = []
	sm = 0
	for i in range(len(s)):
		if s[i - 1] == s[i]:
			sm += 1
		dp.append(sm)
	for _ in range(m):
		(l, r) = map(int, input().split())
		print(dp[r - 1] - dp[l - 1])
sol()


n = input()
k = int(input())
S = []
T = []
for i in range(k):
	S.append(tuple((int(i) for i in input().split())))
N = {-1: 0}
for i in range(len(n) - 1):
	if n[i] == n[i + 1]:
		N[i] = N[i - 1] + 1
	else:
		N[i] = N[i - 1]
for i in S:
	T.append(str(N[i[1] - 2] - N[i[0] - 2]))
print('\n'.join(T))


from sys import stdin, stdout
a = list(input())
n = int(input())
l = [0] * len(a)
k = 0
for i in range(1, len(a)):
	if a[i] == a[i - 1]:
		k += 1
	l[i] = k
for _ in range(n):
	(x, y) = map(int, stdin.readline().split())
	stdout.write(str(l[y - 1] - l[x - 1]) + '\n')


s = input()
pre = [0] * (len(s) + 1)
for i in range(1, len(s)):
	pre[i] = pre[i - 1]
	if s[i - 1] == s[i]:
		pre[i] += 1
q = int(input())
ans = []
for i in range(q):
	(a, b) = map(int, input().split())
	ans.append(str(pre[b - 1] - pre[a - 1]))
print('\n'.join(ans))


x = input()
l = len(x)
a = [0] * l
s = 0
for i in range(l - 1):
	if x[i] == x[i + 1]:
		s += 1
	a[i + 1] = s
m = int(input())
for _ in range(m):
	p = input().split(' ')
	print(a[int(p[1]) - 1] - a[int(p[0]) - 1])


s = input()
m = int(input())
q = []
for i in range(m):
	(c, d) = map(int, input().split())
	q.append([c, d])
a = [0]
cnt = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		cnt += 1
	a.append(cnt)
for i in range(m):
	print(a[q[i][1] - 1] - a[q[i][0] - 1])


s = input()
m = int(input())
ll = [0]
for i in range(len(s) - 1):
	ll += [ll[-1] + (s[i] == s[i + 1])]
a = ''
for z in range(m):
	(l, r) = map(int, input().split())
	a += str(ll[r - 1] - ll[l - 1]) + '\n'
print(a)


a = [0]
s = input()
c = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		c = c + 1
	a.append(c)
m = int(input())
for i in range(m):
	(x, y) = map(int, input().split())
	print(a[y - 1] - a[x - 1])


from sys import stdin, stdout
tokens = stdin.read().split()
s = tokens[0]
n = len(s)
C = [0] * n
for j in range(n - 2, -1, -1):
	C[j] = C[j + 1] + (s[j] == s[j + 1])
n = int(tokens[1])
for i in range(2, 2 + 2 * n, 2):
	l = int(tokens[i])
	r = int(tokens[i + 1])
	print(C[l - 1] - C[r - 1])


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	s = input()
	arr = [[0, 1][s[i] == s[i + 1]] for i in range(len(s) - 1)] + [0]
	for i in range(1, len(arr)):
		arr[i] += arr[i - 1]
	for _ in range(int(input())):
		(a, b) = read()
		a -= 1
		print(arr[b - 2] - [arr[a - 1], 0][a == 0])
solve()


s = input()
x = 0
L = [0]
for k in range(len(s) - 1):
	if s[k] == s[k + 1]:
		x += 1
	L.append(x)
n = int(input())
o = ''
for k in range(n):
	(a, b) = map(int, input().split(' '))
	o += str(L[b - 1] - L[a - 1]) + '\n'
print(o)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
s = data()
arr = [0] * len(s)
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		arr[i] = arr[i - 1] + 1
	else:
		arr[i] = arr[i - 1]
if len(arr) > 1:
	arr[-1] = arr[-2]
arr.insert(0, 0)
for _ in range(int(data())):
	(l, r) = sp()
	answer = arr[r] - arr[l - 1]
	if r < len(s) and s[r - 1] == s[r]:
		answer -= 1
	out(answer)


s = input()
m = int(input())
k = 0
a = [0]
for j in range(1, len(s)):
	if s[j] == s[j - 1]:
		k += 1
	a.append(k)
for i in range(m):
	(l, r) = map(int, input().split())
	print(a[r - 1] - a[l - 1])


s = input()
a = int(input())
dp = [0] * len(s)
c = 0
for x in range(1, len(s)):
	if s[x] == s[x - 1]:
		c += 1
	dp[x] = c
for x in range(a):
	p = input().split(' ')
	l = int(p[0])
	r = int(p[1])
	print(dp[r - 1] - dp[l - 1])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def abs(x):
	return x if x >= 0 else -x

def sumelem(x, start, end):
	sum = 0
	for i in range(start, end + 1):
		sum += x[i]
	return sum
for t in range(1):
	string = input()
	pref = [0]
	for i in range(len(string) - 1):
		if string[i] == string[i + 1]:
			pref.append(pref[-1] + 1)
		else:
			pref.append(pref[-1])
	m = int(input())
	for i in range(m):
		(l, r) = list(map(int, input().split()))
		print(pref[r - 1] - pref[l - 1])


n = input()
m = int(input())
y = [0] * len(n)
for i in range(0, len(n) - 1):
	if n[i] == n[i + 1]:
		y[i + 1] = y[i] + 1
	else:
		y[i + 1] = y[i]
for i in range(0, m):
	(l, r) = map(int, input().split())
	print(y[r - 1] - y[l - 1])


s = input()
dp = [0 for x in range(len(s) + 1)]
for i in range(1, len(s)):
	dp[i] = dp[i - 1] + (s[i] == s[i - 1])
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	print(dp[r - 1] - dp[l - 1])


s = input()
m = int(input())
ans = []
li = []
for _ in range(m):
	li.append(list(map(int, input().split())))
le = len(s) - 1
a = [0] * le

def dp():
	for n in range(le, 0, -1):
		y = 0
		if s[n - 1] == s[n]:
			y = 1
		if n == le:
			a[n - 1] = y
		else:
			a[n - 1] = y + a[n]
a.append(0)
dp()
for x in li:
	l = x[0]
	r = x[1]
	print(a[l - 1] - a[r - 1])


s = list(input())
n = len(s)
preproc = [0 for i in range(n)]
for i in range(n - 1):
	if i == 0:
		if s[i] == s[i + 1]:
			preproc[i] = 1
		else:
			pass
	elif s[i] == s[i + 1]:
		preproc[i] = preproc[i - 1] + 1
	else:
		preproc[i] = preproc[i - 1]
m = int(input())
s = ''
for k in range(m):
	(l, r) = list(map(int, input().split()))
	l -= 1
	r -= 1
	if l != 0:
		s += str(preproc[r - 1] - preproc[l - 1]) + '\n'
	else:
		s += str(preproc[r - 1]) + '\n'
print(s[:-1])


from collections import defaultdict as dc
from heapq import *
import math
import bisect
import sys
from collections import deque as dq
from heapq import heapify, heappush, heappop
mod = 10 ** 12

def inp():
	p = int(sys.stdin.readline())
	return p

def line():
	p = list(map(int, sys.stdin.readline().split()))
	return p

def digit(n):
	s = str(n)
	p = 0
	for i in s:
		p += int(i) ** 2
	return p
s = str(input())
n = len(s)
q = inp()
p = [[0, 0] for i in range(n + 1)]
for i in range(n - 1):
	if s[i] == s[i + 1]:
		if s[i] == '.':
			p[i + 1][0] = p[i][0] + 1
			p[i + 1][1] = p[i][1]
		else:
			p[i + 1][1] = p[i][1] + 1
			p[i + 1][0] = p[i][0]
	else:
		p[i + 1][0] = p[i][0]
		p[i + 1][1] = p[i][1]
p[n][0] = p[n - 1][0]
p[n][1] = p[n - 1][1]
for i in range(q):
	(l, r) = line()
	l = l - 1
	r = r - 1
	print(sum(p[r]) - sum(p[l]))


l = [0 if x == '.' else 1 for x in input()]
l[0] = 1 if l[0] == l[1] else 0
for i in range(1, len(l) - 1):
	c = l[i]
	l[i] = l[i - 1]
	if c == l[i + 1]:
		l[i] += 1
l[-1] = l[-2]
n = int(input())
l = [0] + l
results = []
for _ in range(n):
	(i1, i2) = map(int, input().split())
	results.append(str(l[i2 - 1] - l[i1 - 1]))
print('\n'.join(results))


string = input()
list1 = [0]
count = 0
for _ in range(1, len(string)):
	if string[_] == string[_ - 1]:
		count += 1
		list1.append(count)
	else:
		list1.append(count)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(list1[b - 1] - list1[a - 1])


s = input()
l = [0]
s = ' ' + s
n = len(s)
for i in range(1, n):
	if s[i] == s[i - 1]:
		l.append(l[i - 1] + 1)
	else:
		l.append(l[i - 1])
q = int(input())
for i in range(q):
	(a, b) = map(int, input().split())
	print(l[b] - l[a])


s = input()
c = [0] * len(s)
z = 0
for i in range(1, len(s)):
	c[i] = z
	if s[i] == s[i - 1]:
		c[i] += 1
		z += 1
		if z == 1:
			co = i
x = int(input())
f = ''
if z == 0:
	for q in range(x):
		f += '0\n'
	print(f[:-1])
else:
	for j in range(x):
		k = list(map(int, input().split()))
		a = k[0] - 1
		b = k[1] - 1
		f += str(c[b] - c[a]) + '\n'
	print(f[:-1])


def CF313B():
	string = input()
	n = int(input())
	query = [map(int, input().split()) for _ in range(n)]
	arr = [0]
	for i in range(1, len(string)):
		if string[i] == string[i - 1]:
			arr.append(arr[-1] + 1)
		else:
			arr.append(arr[-1])
	for (l, r) in query:
		print(arr[r - 1] - arr[l - 1])
res = CF313B()


s = input()
import itertools
p = [0] * (len(s) + 1)
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		p[i + 1] = 1
p = list(itertools.accumulate(p))
p[-1] = p[0]
for i in range(int(input())):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	print(p[r] - p[l])


s = input('')
m = int(input(''))
b = [0]
c = []
count = 0
for i in range(1, len(s)):
	if s[i] is s[i - 1]:
		count += 1
		b.append(count)
	elif s[i] is not s[i - 1]:
		b.append(count)
for _ in range(m):
	m = [int(x) for x in input().split()]
	v = b[m[1] - 1] - b[m[0] - 1]
	c.append(v)
for all in c:
	print(all)


ss = input()
aa = [0] * len(ss)
for i in range(1, len(ss)):
	aa[i] = aa[i - 1] + [0, 1][ss[i] == ss[i - 1]]
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	print(aa[m - 1] - aa[n - 1])


s = input()
S = [0 for i in range(0, len(s))]
n = int(input())
if s[0] == s[1]:
	S[0] = 1
else:
	S[1] = 0
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		S[i] = S[i - 1] + 1
	else:
		S[i] = S[i - 1]
lr = []
for i in range(0, n):
	lr.append(input().split())
	lr[i][0] = int(lr[i][0])
	lr[i][1] = int(lr[i][1])
for i in range(0, n):
	print(S[lr[i][1] - 1] - S[lr[i][0] - 1])