Vasya likes the number $239$. Therefore, he considers a number pretty if its last digit is $2$, $3$ or $9$. 
Vasya wants to watch the numbers between $L$ and $R$ (both inclusive), so he asked you to determine how many pretty numbers are in this range. Can you help him?

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first and only line of each test case contains two space-separated integers $L$ and $R$.

-----Output-----
For each test case, print a single line containing one integer — the number of pretty numbers between $L$ and $R$.

-----Constraints-----
- $1 \le T \le 100$
- $1 \le L \le R \le 10^5$

-----Subtasks-----
Subtask #1 (100 points): original constraints

-----Example Input-----
2
1 10
11 33

-----Example Output-----
3
8

-----Explanation-----
Example case 1: The pretty numbers between $1$ and $10$ are $2$, $3$ and $9$.
Example case 2: The pretty numbers between $11$ and $33$ are $12$, $13$, $19$, $22$, $23$, $29$, $32$ and $33$.

Source: codechef | Difficulty: EASY
Tags: Range queries

Complete search


Solutions:
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	count = 0
	s = [2, 3, 9]
	for i in range(l, r + 1):
		if i % 10 in s:
			count += 1
	print(count)


t = int(input())
for i in range(0, t):
	c = 0
	(a, b) = map(int, input().split())
	for j in range(a, b + 1):
		if j % 10 == 2 or j % 10 == 3 or j % 10 == 9:
			c += 1
	print(c)


for i in range(int(input())):
	(m, n) = list(map(int, input().split()))
	c = 0
	for i in range(m, n + 1):
		p = str(i)
		if p[-1] == '2' or p[-1] == '3' or p[-1] == '9':
			c = c + 1
	print(c)


t = int(input())
for i in range(t):
	(l, r) = map(int, input().split())
	num = 0
	for i in range(l, r + 1):
		if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
			num = num + 1
	print(num)


n = int(input())
for i in range(0, n):
	c = 0
	(x, y) = map(int, input().split())
	for i in range(x, y + 1):
		i = str(i)
		if i[-1] == '2' or i[-1] == '3' or i[-1] == '9':
			c += 1
	print(c)
	c = 0


def pretty(a, b):
	count = 0
	for i in range(a, b + 1):
		if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
			count += 1
	return count
cases = int(input())
for i in range(cases):
	(a, b) = input().split()
	print(pretty(int(a), int(b)))


def __starting_point():
	t = int(input())
	for m in range(t):
		(l, r) = list(map(int, input().split(' ')))
		co = 0
		for i in range(l, r + 1):
			if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
				co += 1
		print(co)

def pretty(n):
	if n % 10 == 2 or n % 10 == 3 or n % 10 == 9:
		return True
	else:
		return False
__starting_point()


t = int(input())
while t:
	(l, r) = input().split()
	l = int(l)
	r = int(r)
	count = 0
	for i in range(l, r + 1):
		rem = i % 10
		if rem == 2 or rem == 3 or rem == 9:
			count = count + 1
	print(count)
	t = t - 1


n = int(input())
a = []
q = [2, 3, 9]
for i in range(n):
	(b, c) = map(int, input().split())
	count = 0
	for j in range(b, c + 1):
		x = str(j)
		if int(x[len(x) - 1]) in q:
			count += 1
	print(count)


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	c = 0
	for i in range(l, r + 1):
		if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
			c = c + 1
	print(c)


for item in range(int(input())):
	(l, r) = map(int, input().split())
	x = 0
	for i in range(l, r + 1):
		convert = i % 10
		if convert == 2:
			x += 1
		if convert == 3:
			x += 1
		if convert == 9:
			x += 1
	print(x)


t = int(input())
for i in range(t):
	count = 0
	l = [int(z) for z in input().split()]
	(a, b) = (l[0], l[1])
	for j in range(a, b + 1):
		if j % 10 == 2 or j % 10 == 3 or j % 10 == 9:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(l, r) = map(int, input().split())
	count = 0
	for k in range(l, r + 1):
		str1 = str(k)
		ln = len(str1) - 1
		if str1[ln] == '2' or str1[ln] == '3' or str1[ln] == '9':
			count += 1
	print(count)


for j in range(int(input())):
	count = 0
	(l, r) = map(int, input().split())
	for i in range(l, r + 1, 1):
		a = str(i)
		if a[-1] == '2' or a[-1] == '3' or a[-1] == '9':
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	count = 0
	for i in range(n, m + 1):
		p = str(i)
		if p[-1] == '2' or p[-1] == '3' or p[-1] == '9':
			count += 1
	print(count)


t = int(input())
if t >= 1 and t <= 100:
	for _ in range(t):
		(l, r) = map(int, input().split())
		c = 0
		if l >= 1 and l <= r and (r <= pow(10, 5)):
			for i in range(l, r + 1, 1):
				if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
					c += 1
			print(c)


n = int(input())
for i in range(n):
	(l, r) = list(map(int, input().split()))
	c = 0
	s = [2, 3, 9]
	for i in range(l, r + 1):
		if i % 10 in s:
			c = c + 1
	print(c)


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	ls = [2, 3, 9]
	ls1 = []
	for i in range(l, r + 1):
		ls1.append(i)
	count = 0
	for i in ls1:
		j = str(i)
		if j[-1] == '2' or j[-1] == '3' or j[-1] == '9':
			count += 1
	print(count)


a = int(input())
for i in range(a):
	(x, y) = map(int, input().split())
	count = 0
	l = [2, 3, 9]
	for i in range(x, y + 1):
		if i % 10 in l:
			count += 1
	print(count)


t = int(input())
runner = 1
while runner <= t and t > 0 and (t <= 100):
	inp = input().split()
	L = int(inp[0])
	R = int(inp[1])
	if L < 1 or L > R or R > 10 ** 5:
		break
	count = 0
	for i in range(L, R + 1):
		if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
			count += 1
	print(count)
	runner += 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	for i in range(a, b + 1):
		if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
			count += 1
	print(count)


for i in range(int(input())):
	(L, R) = map(int, input().split())
	count = 0
	l = [2, 3, 9]
	for i in range(L, R + 1):
		if i % 10 in l:
			count += 1
	print(count)


n = int(input())
for _ in range(n):
	arr = list(map(int, input().split()))
	a = [2, 3, 9]
	count = 0
	for i in range(arr[0], arr[-1] + 1):
		if i % 10 in a:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	pn = 0
	for i in range(a, b + 1):
		if i % 10 in [2, 3, 9]:
			pn += 1
	print(pn)


t = int(input())
for i in range(t):
	(l, r) = list(map(int, input().split()))
	ans = 0
	for i in range(l, r + 1):
		ck = str(i)[-1]
		if ck == '2' or ck == '3' or ck == '9':
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	c = 0
	l = [2, 3, 9]
	for i in range(x, y + 1):
		if i % 10 in l:
			c += 1
	print(c)


for _ in range(int(input())):
	(x, y) = map(int, input().split(' '))
	count = 0
	for i in range(x, y + 1):
		if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
			count += 1
	print(count)


for x in range(int(input())):
	(l, r) = map(int, input().split())
	c = 0
	if l - r <= 0:
		for y in range(l, r + 1):
			if y % 10 in [2, 3, 9]:
				c += 1
	else:
		c = 3 * (r // 10 - l // 10)
		for y in range(l % 10):
			if y in [2, 3, 9]:
				c -= 1
		for y in range(r % 10):
			if y in [2, 3, 9]:
				c += 1
	print(c)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	count = 0
	for i in range(a, b + 1):
		s = str(i)
		if len(s) == 1:
			if s == str(2) or s == str(3) or s == str(9):
				count += 1
		elif len(s) > 1:
			if s[-1] == str(2) or s[-1] == str(3) or s[-1] == str(9):
				count += 1
	print(count)


t = int(input())
while t > 0:
	(l, r) = map(int, input().split())
	count = 0
	for i in range(l, r + 1):
		if i == 3 or i == 2 or i == 9:
			count += 1
		else:
			n = i % 10
			if n == 2 or n == 3 or n == 9:
				count += 1
	print(count)
	t = t - 1


x = int(input())
lst = []
for i in range(0, x):
	(l, r) = input().split()
	l = int(l)
	r = int(r)
	sublst = []
	while l <= r:
		if l % 10 == 2 or l % 10 == 3 or l % 10 == 9:
			sublst.append(l)
		l += 1
	lst.append(len(sublst))
for i in range(0, x):
	print(lst[i])


t = int(input())
for i in range(t):
	(l, r) = map(int, input().split())
	c = 0
	m = [2, 3, 9]
	for i in range(l, r + 1):
		if i % 10 in m:
			c += 1
	print(c)


t = int(input())
while t > 0:
	(l, r) = tuple([int(i) for i in input().split()])
	c = 0
	for i in range(l, r + 1):
		num = list(str(i))[-1]
		if '2' == num or '3' == num or '9' == num:
			c += 1
	print(c)
	t -= 1


for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	for i in range(a, b + 1):
		s = str(i)
		if s[-1] == '2' or s[-1] == '3' or s[-1] == '9':
			c += 1
	print(c)


T = int(input())
for j in range(T):
	ran = list(map(int, input().rstrip().split()))
	count = 0
	for i in range(ran[0], ran[1] + 1):
		if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
			count += 1
	print(count)


T = int(input())
for i in range(T):
	(L, R) = map(int, input().split(' '))
	p = [2, 3, 9]
	l = []
	count = 0
	for i in range(L, R + 1):
		l.append(i)
	for i in l:
		j = str(i)
		if j[-1] == '2' or j[-1] == '3' or j[-1] == '9':
			count += 1
	print(count)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	C = 0
	for j in range(x, y + 1):
		if j % 10 == 2 or j % 10 == 3 or j % 10 == 9:
			C = C + 1
	print(C)


t = int(input())
for i in range(t):
	x = input()
	z = x.split()
	a = int(z[0])
	b = int(z[1])
	d = ['2', '3', '9']
	c = 0
	for i in range(a, b + 1):
		w = str(i)
		if w[-1] in d:
			c += 1
	print(c)


t = int(input())
for i in range(t):
	(l, r) = map(int, input().split())
	count = 0
	for i in range(l, r + 1):
		str_i = str(i)
		if str_i[-1] == '2' or str_i[-1] == '3' or str_i[-1] == '9':
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	(L, R) = map(int, input().split())
	count = 0
	for i in range(L, R + 1):
		if str(i)[-1] == '2':
			count = count + 1
		elif str(i)[-1] == '3':
			count = count + 1
		elif str(i)[-1] == '9':
			count = count + 1
	print(count)


for i in range(int(input())):
	(m, n) = map(int, input().split())
	count = 0
	for z in range(m, n + 1):
		if z % 10 == 2 or z % 10 == 3 or z % 10 == 9:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	i = n
	count = 0
	while i <= k:
		l = list(str(i))
		if l[-1] in ['2', '3', '9']:
			count += 1
		i += 1
	print(count)


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	c = 0
	while l <= r:
		i = 1
		if str(l)[-1] == '2':
			c += 1
			i = 1
		elif str(l)[-1] == '3':
			c += 1
			i = 6
		elif str(l)[-1] == '9':
			c += 1
			i = 3
		l += i
	print(c)


vp = int(input())
for i in range(vp):
	(t, a) = map(int, input().split())
	cou = 0
	for j in range(t, a + 1):
		if j % 10 == 2 or j % 10 == 3 or j % 10 == 9:
			cou = cou + 1
	print(cou)


t = int(input())
flag = 0
for i in range(0, t):
	(a, b) = list(map(int, input().split()))
	for i in range(a, b + 1):
		if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
			flag += 1
	print(flag)
	flag = 0


T = int(input())
for i in range(T):
	(L, R) = map(int, input().split())
	count = 0
	l1 = []
	for i in range(L, R + 1):
		l1.append(i)
	for i in l1:
		if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
			count += 1
	print(count)


n = int(input())
for _ in range(n):
	(n1, n2) = map(int, input().split())
	c = 0
	for j in range(n1, n2 + 1):
		if j % 10 in [2, 3, 9]:
			c += 1
	print(c)


T = int(input())
for i in range(T):
	(l, r) = map(int, input().split())
	p = 0
	for j in range(l, r + 1):
		if j % 10 == 2 or j % 10 == 3 or j % 10 == 9:
			p = p + 1
	print(p)


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


T = int(input())
for i in range(T):
	lr = list(map(int, input().split()))
	counter = 0
	for j in range(lr[0], lr[1] + 1):
		if j % 10 == 2 or j % 10 == 3 or j % 10 == 9:
			counter += 1
	print(counter)


import numpy as np
for i in range(int(input())):
	(m, p) = map(int, input().split())
	a = [2, 3, 9]
	count = 0
	for x in range(m, p + 1):
		if x % 10 in a:
			count += 1
	print(count)


a = int(input())
for _ in range(a):
	(a1, a2) = map(int, input().split())
	c = 0
	for j in range(a1, a2 + 1):
		if j % 10 in [2, 3, 9]:
			c += 1
	print(c)


for i in range(int(input())):
	(l, n) = list(map(int, input().split()))
	c = 0
	v = '239'
	for j in range(l, n + 1):
		a = len(str(j))
		k = j % 10
		if str(k) in v:
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	i = l
	count = 0
	while i <= r:
		remain = i % 10
		if remain in [2, 3, 9]:
			count += 1
		i += 1
	print(count)


t = int(input())
for j in range(t):
	(l, r) = list(map(int, input().split()))
	c = 0
	for i in range(l, r + 1):
		if i % 10 == 2 or i % 10 == 3 or i % 10 == 9:
			c += 1
	print(c)


def prettynumber(m, n):
	count = 0
	for i in range(m, n + 1):
		x = i % 10
		if x == 2 or x == 3 or x == 9:
			count += 1
	print(count)

def __starting_point():
	for j in range(int(input())):
		ab = input().split()
		a = int(ab[0])
		b = int(ab[1])
		prettynumber(a, b)
__starting_point()