On March 14, the day of the number $\pi$ is celebrated all over the world. This is a very important mathematical constant equal to the ratio of the circumference of a circle to its diameter.

Polycarp was told at school that the number $\pi$ is irrational, therefore it has an infinite number of digits in decimal notation. He wanted to prepare for the Day of the number $\pi$ by memorizing this number as accurately as possible.

Polycarp wrote out all the digits that he managed to remember. For example, if Polycarp remembered $\pi$ as $3.1415$, he wrote out 31415.

Polycarp was in a hurry and could have made a mistake, so you decided to check how many first digits of the number $\pi$ Polycarp actually remembers correctly.


-----Input-----

The first line of the input data contains the single integer $t$ ($1 \le t \le 10^3$) — the number of test cases in the test.

Each test case is described by a single string of digits $n$, which was written out by Polycarp.

The string $n$ contains up to $30$ digits.


-----Output-----

Output $t$ integers, each of which is the answer to the corresponding test case, that is how many first digits of the number $\pi$ Polycarp remembers correctly.


-----Examples-----

Input
9
000
3
4141592653
141592653589793238462643383279
31420
31415
314159265358
27182
314159265358979323846264338327
Output
0
1
0
0
3
5
12
0
30


-----Note-----

None

Difficulty: EASY
Tags: Mathematics

String algorithms

Implementation

Starter code:

Solutions:
rn = '314159265358979323846264338327'
for _ in range(int(input())):
	c = 0
	for i in input():
		try:
			if i == rn[c]:
				c += 1
			else:
				break
		except:
			break
	print(c)


for _ in range(int(input())):
	n = input()
	pi = '314159265358979323846264338327'
	c = 0
	for i in range(len(n)):
		if n[i] == pi[i]:
			c += 1
		else:
			break
	print(c)


t = int(input())
while t > 0:
	str = input()
	pi = '314159265358979323846264338327'
	p = 0
	while p < len(str):
		if pi[p] == str[p]:
			p += 1
		else:
			break
	print(p)
	t -= 1


t = int(input())
p = '314159265358979323846264338327'
count = 0
for i in range(t):
	k = input()
	k = str(k)
	for i in range(len(k)):
		if p[i] == k[i]:
			count += 1
		else:
			break
	print(count)
	count = 0


def main() -> str:
	t = int(input())
	for i in range(t):
		n = str(input())
		pi30 = '314159265358979323846264338327'
		cnt = 0
		for j in range(len(n)):
			if n[j] == pi30[j]:
				cnt += 1
			else:
				break
		print(cnt)
main()


p = '314159265358979323846264338327'
for _ in range(int(input())):
	s = input()
	c = 0
	for x in range(len(s)):
		if p[x] == s[x]:
			c += 1
		else:
			break
	print(c)


t = int(input())
pi = '31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'
for _ in range(t):
	n = input() + '#'
	for i in range(len(n)):
		if pi[i] != n[i]:
			print(i)
			break


pi = '314159265358979323846264338327'
for _ in range(int(input())):
	(ans, s) = (0, input())
	for i in range(30):
		try:
			if pi[i] == s[i]:
				ans += 1
			else:
				break
		except:
			break
	print(ans)


t = int(input())
for i in range(t):
	l = input()
	e = '314159265358979323846264338327'
	out = 30
	for i in range(len(l)):
		if l[i] != e[i]:
			out = i
			break
	print(min(out, len(l)))


s = '31415926535897932384626433832795028841971693993751 058209749445923078164062862089986280348253421170679'
t = int(input())
for _ in range(t):
	a = input()
	c = 0
	for i in range(len(a)):
		if a[i] == s[i]:
			c += 1
		else:
			break
	print(c)


for _ in range(int(input())):
	s = input()
	s1 = '3141592653589793238462643383279'
	ans = -1
	for i in range(len(s)):
		if s[i] != s1[i]:
			break
		ans = i
	print(ans + 1)


import math
import collections
for _ in range(int(input())):
	s = input()
	x = '314159265358979323846264338327'
	ans = 0
	for i in range(len(s)):
		if s[i] == x[i]:
			ans += 1
		else:
			break
	print(ans)


pi = '31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'

def main():
	_i = int(input())
	for _ in range(_i):
		res = 0
		s = input().strip('\r\n')
		for i in range(len(s)):
			if s[i] != pi[i]:
				break
			res += 1
		print(res)
main()


def func(a):
	check = '314159265358979323846264338327'
	count = 0
	for z in range(len(a)):
		if a[z] == check[z]:
			count += 1
		else:
			return count
	return count
for _ in range(int(input())):
	a = str(input())
	print(func(a))


p = '314159265358979323846264338327'
t = int(input())
for i in range(t):
	s = input()
	u = 0
	for (i, c) in enumerate(s):
		if c == p[i]:
			u += 1
		else:
			print(u)
			break
	else:
		print(u)


import sys
import math
import heapq
import bisect
t = int(input())
for _ in range(t):
	con = '3141592653589793238462643383279'
	s = input()
	ans = 0
	for i in range(len(s)):
		if con[i] == s[i]:
			ans += 1
		else:
			break
	print(ans)


import sys
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7

def readInt():
	return int(input())

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

def readStringList():
	return list(input())

def readStringListWithSpace():
	return list(input().split())

def readString():
	return input()

def execute():
	for _ in range(readInt()):
		cmr = '314159265358979323846264338327'
		n = readStringList()
		count = 0
		for (i, c) in enumerate(n):
			if cmr[i] == c:
				count += 1
			else:
				break
		print(count)
execute()


import functools
import sys
from collections import defaultdict
import collections
import math
import heapq
from collections import deque
pi = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825'

def solve(N):
	ans = 0
	for (a, b) in zip(pi, N):
		if a == b:
			ans += 1
		else:
			break
	return ans
t = int(input())
for j in range(1, t + 1):
	N = input()
	result = solve(N)
	print(result)


from math import gcd
t = int(input())
for p in range(t):
	s = input()
	a = '31415926535897932384626433832795'
	cnt = 0
	for i in range(len(s)):
		if a[i] == s[i]:
			cnt += 1
		else:
			break
	print(cnt)


x = '314159265358979323846264338327'
for _ in range(int(input())):
	a = input()
	a = a.replace('.', '')
	c = 0
	for i in range(len(a)):
		if a[i] == x[i]:
			c += 1
		else:
			break
	print(c)


a = '314159265358979323846264338327'
for k in range(int(input())):
	s = input()
	ans = 0
	for (i, j) in zip(a, s):
		if i == j:
			ans += 1
		else:
			break
	print(ans)


pi = '31415926535897932384626433832795028841971'
t = int(input())
for i in range(t):
	numbers = input().strip()
	count = 0
	for i in range(len(numbers)):
		if numbers[i] == pi[i]:
			count += 1
		else:
			break
	print(count)


def ip():
	return int(input())

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

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

def f(a):
	s = '314159265358979323846264338327'
	for i in range(len(a)):
		if a[i] != s[i]:
			return i
	return len(a)
for i in range(ip()):
	a = input()
	print(f(a))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from collections import Counter
from bisect import bisect_left as bl, bisect_right as br
import heapq
from itertools import permutations
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007
test = int(input())
for _ in range(test):
	s = input()
	c = 0
	ans = '3141592653589793238462643383279'
	for i in range(len(s)):
		if s[i] == ans[i]:
			c += 1
		else:
			break
	print(c)


def N():
	return int(input())

def A():
	return [int(x) for x in input().split()]

def S():
	return input()
for _ in range(N()):
	n = S()
	if 'codeforces' == 28226329:
		print('Tanmay')
	p = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825'
	c = 0
	for i in range(len(n)):
		if p[i] == n[i]:
			c += 1
		else:
			break
	print(c)


for _ in range(int(input())):
	pi = '3141592653589793238462643383279'
	s = input()
	c = 0
	for i in range(len(s)):
		if s[i] == pi[i]:
			c += 1
		else:
			break
	print(c)


t = int(input())
for i in range(t):
	s = input()
	act = '3141592653589793238462643383279'
	ans = 0
	n = len(s)
	for j in range(n):
		if s[j] == act[j]:
			ans += 1
		else:
			break
	print(ans)


import math
for _ in range(int(input())):
	a = input()
	ans = '3141592653589793238462643383279'
	count = 0
	for i in range(len(a)):
		if a[i] == ans[i]:
			count += 1
		else:
			break
	print(count)


t = int(input())
for o in range(t):
	n = input()
	ans = 0
	p = '31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679'
	for (i, s) in enumerate(n):
		if s == p[i]:
			ans += 1
		else:
			break
	print(ans)


t = int(input())
for test in range(t):
	n = input()
	x = '314159265358979323846264338327'
	otv = 0
	for i in range(len(n)):
		if n[:i + 1] == x[:i + 1]:
			otv = i + 1
	print(otv)


pi = '31415926535897932384626433832795028841971'
for _ in range(int(input())):
	c = 0
	for (i, j) in zip(input(), pi):
		if i == j:
			c += 1
		else:
			break
	print(c)


import sys
import threading
from math import *
from bisect import *
from collections import *
from heapq import *
from functools import *

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

def gi():
	return int(input())

def gc():
	return input()
mod = int(pow(10, 9)) + 7

def solution():
	w = gc()
	correct = '314159265358979323846264338327'
	ans = 0
	for i in range(len(w)):
		if w[i] == correct[i]:
			ans += 1
		else:
			return print(ans)
	return print(ans)

def main():
	t = gi()
	for _ in range(t):
		solution()
threading.stack_size(1 << 27)
sys.setrecursionlimit(1 << 30)
main_thread = threading.Thread(target=main)
main_thread.start()
main_thread.join()


for i in range(int(input())):
	l = list(input())
	s = '3141592653589793238462643383279'
	c = 0
	for i in range(len(l)):
		if l[i] == s[i]:
			c += 1
		else:
			break
	print(c)


import sys
import collections
from math import ceil, gcd, sqrt, log
import bisect
import heapq
INF = float('inf')
mod = 1000000007

def solve():
	s = input()
	net = '3141592653589793238462643383279'
	count = 0
	for i in range(len(s)):
		if s[i] != net[i]:
			break
		count += 1
	print(count)
t = int(input())
while t != 0:
	solve()
	t -= 1


x = '314159265358979323846264338327'
for _ in range(int(input())):
	n = input()
	count = 0
	for i in range(len(n)):
		if n[i] == x[i]:
			count += 1
		else:
			break
	print(count)


import sys
PI = '314159265358979323846264338327'
for _ in range(int(input())):
	pi = input()
	count = 0
	for i in range(len(pi)):
		if pi[i] != PI[i]:
			break
		count += 1
	sys.stdout.write(f'{count}\n')


s1 = '314159265358979323846264338327'
for _ in range(int(input())):
	s2 = input()
	ctr = 0
	for i in range(len(s2)):
		if s2[i] == s1[i]:
			ctr += 1
		else:
			break
	print(ctr)


for _ in range(int(input())):
	p = '314159265358979323846264338327'
	n = input()
	ct = 0
	for i in range(len(n)):
		if n[i] == p[i]:
			ct += 1
		else:
			break
	print(ct)


val = '314159265358979323846264338327'
for _ in range(int(input())):
	s = input()
	left = 0
	while left < len(s):
		if val[left] != s[left]:
			break
		left += 1
	print(left)


for _ in range(int(input())):
	s = input()
	pi = '314159265358979323846264338327'
	n = len(s)
	cnt = 0
	for i in range(min(n, 30)):
		if s[i] != pi[i]:
			break
		cnt += 1
	print(cnt)


t = int(input())
for _ in range(t):
	n = input()
	pi = '3141592653589793238462643383279'
	res = 0
	for i in range(len(n)):
		if n[i] == pi[i]:
			res += 1
		else:
			break
	print(res)


import math

def primeFactors(n):
	l = []
	c = 2
	while n > 1:
		if n % c == 0:
			l.append(c)
			n = n / c
		else:
			c = c + 1
	return l

def primeFactors(n):
	l = []
	c = 2
	while n > 1:
		if n % c == 0:
			l.append(c)
			n = n / c
		else:
			c = c + 1
	return l

def prime(n):
	prime_flag = 0
	if n > 1:
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				prime_flag = 1
				break
	return prime_flag
t = int(input())
while t:
	pi = '314159265358979323846264338327'
	s = input()
	count = 0
	m = min(len(s), len(pi))
	for i in range(m):
		if s[i] == pi[i]:
			count += 1
		else:
			break
	print(count)
	t = t - 1


t = int(input())
doporownania = '314159265358979323846264338327'
for i in range(t):
	n = input()
	licznik = 0
	for j in range(len(n)):
		if doporownania[j] == n[j]:
			licznik += 1
		else:
			break
	print(licznik)


p = '3141592653589793238462643383279'
t = int(input())
while t > 0:
	n = input()
	match = len(n)
	for i in range(len(n)):
		if n[i] != p[i]:
			match = i
			break
	print(match)
	t -= 1


t = int(input())
while t > 0:
	pi = '314159265358979323846264338327'
	n = 0
	inp = input()
	for i in range(len(inp)):
		if inp[i] == pi[i]:
			n += 1
		else:
			break
	print(n)
	t -= 1


for _ in range(int(input())):
	pi = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647'
	s = input()
	res = 0
	for i in range(len(s)):
		if s[i] == pi[i]:
			res += 1
		else:
			break
	print(res)


t = int(input())
st = '314159265358979323846264338327'
for t1 in range(t):
	s = input()
	ind = 0
	for i in range(len(s)):
		if s[i] != st[i]:
			print(i)
			ind = 1
			break
	if ind == 0:
		print(len(s))


for aa in range(int(input())):
	n = input()
	x = '314159265358979323846264338327'
	c = 0
	for i in range(len(n)):
		if n[i] == x[i]:
			c += 1
		else:
			break
	print(c)


for _ in range(int(input())):
	k = '314159265358979323846264338327'
	s = input()
	c = 0
	for i in range(len(s)):
		if s[i] != k[i]:
			break
		c += 1
	print(c)


answer = list(str(314159265358979323846264338327))
n = int(input())
for i in range(n):
	a = list(str(input()))
	count = 0
	for j in range(len(a)):
		if answer[j] == a[j]:
			count += 1
		else:
			break
	print(count)


for _ in range(int(input())):
	s = '314159265358979323846264338327'
	n = input()
	c = 0
	while c < len(n) and s[c] == n[c]:
		c += 1
	print(c)


t = int(input())
pi = '314159265358979323846264338327'
for i in range(t):
	n = input()
	c = 0
	for j in range(len(n)):
		if n[j] != pi[j]:
			break
		c += 1
	print(c)


for _ in range(int(input())):
	s = input()
	a = '314159265358979323846264338327'
	count = 0
	for i in range(len(s)):
		if a[i] == s[i]:
			count += 1
		else:
			break
	print(count)


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

def gi(n):
	return [list(map(int, input().split())) for _ in range(n)]
x = '314159265358979323846264338327'
for _ in range(int(input())):
	n = input()
	ans = 0
	for i in range(len(n)):
		if n[i] == x[i]:
			ans += 1
		else:
			break
	print(ans)


PI = '314159265358979323846264338327950288419716939937510582097494459230781640628620899'

def solve(val):
	if val == '' or val[0] != PI[0]:
		return 0
	i = 0
	j = 0
	for i in range(len(val)):
		if val[i] == PI[i]:
			j += 1
		else:
			break
	return min(j, 30)
n = int(input())
for i in range(n):
	val = input()
	print(solve(val))


for _ in [0] * int(input()):
	n = input()
	pi = '314159265358979323846264338327950288'
	count = 0
	for i in range(len(n)):
		if n[i] == pi[i]:
			count += 1
		else:
			break
	print(count)


pi = '3141592653589793238462643383279'
t = int(input())
for t in range(t):
	s = input()
	ans = 0
	for i in range(len(s)):
		if s[i] == pi[i]:
			ans += 1
		else:
			break
	print(ans)


t = int(input())
for i in range(0, t):
	s = input()
	n1 = '314159265358979323846264338327'
	n = len(s)
	ans = 0
	for j in range(0, n):
		if s[j] == n1[j]:
			ans = ans + 1
		else:
			break
	print(ans)


for i in range(int(input())):
	a = input()
	c = '31415926535897932384626433832795028841971'
	d = 0
	for i in range(len(a)):
		if a[i] == c[i]:
			d += 1
		else:
			break
	print(d)


for _ in range(int(input())):
	lis = ['3', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6', '2', '6', '4', '3', '3', '8', '3', '2', '7']
	n = input()
	n = list(n)
	count = 0
	k = len(n)
	for i in range(len(n)):
		if int(n[i]) == int(lis[i]):
			count += 1
		else:
			break
	print(count)


def main():
	for t in range(int(input())):
		s = input()
		l = '314159265358979323846264338327'
		c = 0
		for i in range(len(s)):
			if s[i] == l[i]:
				c += 1
			else:
				break
		print(c)
main()


p = str(3141592653589793238462643383279)
n = int(input())
for i in range(n):
	x = input()
	z = 0
	for k in range(min(len(x), 31)):
		if x[k] == p[k]:
			z += 1
		else:
			break
	print(z)


t = int(input())
for p in range(t):
	pi = '3141592653589793238462643383279'
	s = input()
	c = 0
	for i in range(0, len(s)):
		if pi[i] != s[i]:
			break
		c += 1
	print(c)


from math import acos
pi = '314159265358979323846264338327'
t = int(input())
for i in range(t):
	s = input()
	ans = 0
	for i in range(len(s)):
		if s[i] == pi[i]:
			ans += 1
		else:
			break
	print(ans)


pi = '314159265358979323846264338327'
for run in range(int(input())):
	n = input()
	val = 0
	for i in range(len(n)):
		if n[i] == pi[i]:
			val += 1
		else:
			break
	print(val)


pi = '3141592653589793238462643383279'
n = int(input())
data = list()
for i in range(n):
	data.append(input())
for i in range(n):
	c = 0
	q = len(data[i])
	for j in range(q):
		if data[i][j] != pi[j]:
			break
		c += 1
	print(c)


p = '3141592653589793238462643383279502884197169399375105820974944592307816406286'
for _ in range(int(input())):
	n = input()
	ct = 0
	i = 0
	while i < len(n) and i < len(p):
		if n[i] == p[i]:
			ct += 1
			i += 1
		else:
			break
	print(ct)


pi = '3141592653589793238462643383279'
T = int(input())
while T > 0:
	T -= 1
	a = input()
	res = 0
	for i in range(len(a)):
		if a[i] == pi[i]:
			res += 1
		else:
			break
	print(res)


mod = int(1000000000.0) + 7
pi = '3141592653589793238462643383279502884197'
tc = int(input())
for _ in range(tc):
	n = input()
	(l, i) = (len(n), 0)
	while i < l:
		if n[i] != pi[i]:
			break
		i += 1
	print(i)


teja = int(input())
for i in range(teja):
	s = input()
	c = 0
	p = '314159265358979323846264338327'
	for i in range(len(s)):
		if s[i] == p[i]:
			c += 1
		else:
			break
	print(c)


for i in range(int(input())):
	n = input()
	s = '314159265358979323846264338327'
	count = 0
	for i in range(len(n)):
		if n[i] == s[i]:
			count += 1
		else:
			break
	print(count)


def solve(n):
	s = '314159265358979323846264338327'
	c = 0
	for i in range(len(n)):
		if n[i] != s[i]:
			return c
		else:
			c += 1
	return c
for i in range(int(input())):
	n = input()
	print(solve(n))


q = int(input())
for i in range(q):
	w = str(input())
	e = len(w)
	r = '314159265358979323846264338327950288419716939937510'
	t = 0
	for i in range(e):
		if w[i] == r[i]:
			t = t + 1
		else:
			break
	print(t)


pi = '314159265358979323846264338327'
for i in range(int(input())):
	numero = input()
	contador = 0
	for e in range(len(numero)):
		if numero[e] == pi[e]:
			contador += 1
			continue
		break
	print(contador)


t = int(input())
for x in range(t):
	s = input()
	pi = '314159265358979323846264338327'
	c = 0
	for i in range(len(s)):
		if s[i] == pi[i]:
			c += 1
		else:
			break
	print(c)


for i in range(int(input())):
	s = '314159265358979323846264338327'
	k = input()
	o = 0
	for i in range(len(k)):
		if k[i] != s[i]:
			break
		else:
			o += 1
	print(o)


case = int(input())
for _ in range(case):
	pie = '314159265358979323846264338327'
	n = input()
	count = 0
	j = 0
	for i in n:
		if i == pie[j]:
			count += 1
		else:
			break
		j += 1
	print(count)


n = int(input())
for i in range(n):
	s = str(input())
	y = '314159265358979323846264338327'
	c = 0
	for k in range(len(s)):
		if s[k] == y[k]:
			c = c + 1
		else:
			break
	print(c)


def finalans(s):
	letpi = '314159265358979323846264338327'
	c = 0
	for i in range(len(s)):
		if s[i] != letpi[i]:
			break
		c += 1
	return c
for _ in range(int(input())):
	s = input()
	print(finalans(s))


s = '314159265358979323846264338327'
for i in range(int(input())):
	a = input()
	n = len(a)
	for j in range(len(a)):
		if a[j] != s[j]:
			n = j
			break
	print(n)


t = int(input())
while t:
	count = 0
	s = input()
	req = '314159265358979323846264338327'
	i = 0
	m = min(len(s), len(req))
	while i < m:
		if req[i] == s[i]:
			count += 1
			i += 1
		else:
			break
	print(count)
	t -= 1


pi = '314159265358979323846264338327'
f = int(input())
for _ in range(f):
	a = input()
	ct = 0
	for i in range(len(a)):
		if pi[i] == a[i]:
			ct += 1
		else:
			break
	print(ct)


t = int(input())
pi_digits = '3141592653589793238462643383279'
for i in range(t):
	n = input()
	count = 0
	for j in range(len(n)):
		if n[j] == pi_digits[j]:
			count += 1
		else:
			break
	print(count)


import math
b = str(31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495)
for i in range(0, int(input())):
	count = 0
	a = input()
	for s in range(len(a)):
		if b[s] == a[s]:
			count += 1
		else:
			break
	print(count)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	p = '314159265358979323846264338327'
	cnt = 0
	for i in range(n):
		if s[i] == p[i]:
			cnt += 1
		else:
			break
	print(cnt)


t = int(input())
for i in range(t):
	s = input()
	cmp = '314159265358979323846264338327'
	c = 0
	for j in range(len(s)):
		if s[j] == cmp[j]:
			c += 1
		else:
			break
	print(c)


import sys, math, cmath, time
from bisect import bisect_left
start_time = time.time()

def solve():
	s = input().strip()
	s1 = '3.14159265358979323846264338327950288419716939937510'
	c = 0
	if s[0] == s1[0]:
		c += 1
	else:
		print(0)
		return
	p = 2
	for i in s[1:]:
		if i == s1[p]:
			c += 1
			p += 1
		else:
			print(c)
			return
	print(c)

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

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

def inps():
	return input().split()
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()