Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

Python: def lcs(X,Y):
    Xlength = len(X)
    Ylength = len(Y)

    for i in range(Xlength+1):
        c[i][0] = 0
    for i in range(Ylength+1):
        c[0][i] = 0

    for i in range(Xlength):
        for j in range(Ylength):
            if X[i] == Y[j]:
                c[i+1][j+1] = c[i][j]+1
            else:
                c[i+1][j+1] = max(c[i][j+1],c[i+1][j])

    return c[Xlength][Ylength]

    # print(X,Y)
    # if Xlength == 0 or Ylength == 0:
    #     c[Xlength][Ylength] = 0
    #     return c[Xlength][Ylength]
    #
    #
    #
    # if X[Xlength -1] == Y[Ylength -1]:
    #     if c[Xlength-1][Ylength-1] is not None:
    #         c[Xlength][Ylength] = c[Xlength-1][Ylength-1]+1
    #     else:
    #         c[Xlength][Ylength] = lcs(X[:Xlength-1], Y[:Ylength-1])+1
    # else:
    #     if c[Xlength-1][Ylength] is not None and c[Xlength][Ylength-1] is not None:
    #         c[Xlength][Ylength] = max(c[Xlength][Ylength-1],c[Xlength-1][Ylength])
    #     elif c[Xlength-1][Ylength] is not None:
    #         c[Xlength][Ylength] = max(lcs(X,Y[:Ylength-1]),c[Xlength-1][Ylength])
    #     elif c[Xlength][Ylength-1] is not None:
    #         c[Xlength][Ylength] = max(c[Xlength][Ylength-1],lcs(X[:Xlength-1],Y))
    #     else:
    #         c[Xlength][Ylength] = max(lcs(X,Y[:Ylength-1]),lcs(X[:Xlength-1],Y))
    #
    # return c[Xlength][Ylength]


n = int(input())
X = []
Y = []
c = [[None]*1001 for i in range(1001)]


for i in range(n):
    X.append(input())
    Y.append(input())

for i in range(n):
    # print(i)
    print(lcs(X[i],Y[i]))
    c = [[None]*1001 for i in range(1001)]

Python: def calc(x,y):
    i = len(x)
    j = len(y)
    if not d[i][j] == None:
        return d[i][j]
    else:
        if x[-1] == y[-1]:
            tmp = calc(x[:-1],y[:-1])+1
            d[i][j] = tmp
            return tmp
        else:
            tmp = max(calc(x[:-1],y),calc(x,y[:-1]))
            d[i][j] = tmp
            return tmp
        
q = int(input())
for i in range(q):
    x = input()
    y = input()
    d = [[0 if i == 0 or j == 0 else None for i in range(len(y)+1)] for j in range(len(x)+1)]
    print(calc(x,y))

Python: q = int(input())

for k in range(q):
    x = input()
    y = input()
    lcs = [0]*(len(x)+1)
    for i in range(len(y)):
        w1 = y[i]
        lcs_2 = lcs[:]
        for j in range(len(x)):
            if x[j] == w1:
                lcs[j+1] = lcs_2[j] + 1  
            elif lcs[j+1] < lcs[j]:
                lcs[j+1] = lcs[j]
    print(lcs[-1])

Python: import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
from bisect import bisect_left
for _ in range(N):
    Xs = input()
    Ys = input()[::-1]
    lis = []
    for x in Xs:
        idx = Ys.find(x)+1
        while idx:
            j = bisect_left(lis, -idx)
            if j>=len(lis):
                lis.append(-idx)
            else:
                lis[j] = -idx
            idx = Ys.find(x, idx)+1
    print(len(lis))

Python: def lcs(str1,str2):
    c=[[0 for _ in range(100000000000)] for _ in range(10000000000000)]
    m=len(str1)
    n=len(str2)
    maxl=0
    str1=" "+str1
    str2=" "+str2

    i=1
    j=1
    while(i<=m):
        while(j<=n):
            if(str1[i]==str2[j]):
                c[i][j]=c[i-1][j-1]+1
              #  print(c[i][j])
            else:
                c[i][j]=max(c[i-1][j],c[i][j-1])
            maxl=max(maxl,c[i][j])
            j+=1
        i+=1
        j=0

    return maxl

def main():
    n=int(input())
    i=0
    while(i<n):
        str1=str(input())
        str2=str(input())
        print(int(lcs(str1,str2)))
        i+=1

main()

Python: e=input
a=[]
for _ in[0]*int(e()):
 X,z=e(),[]
 for y in e():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 a+=[z]
print(*map(len,a),sep='\n')

Python: def solve(x,y):
    lx=len(x)
    ly=len(y)
    dp=[0]*(ly+1)
    for i in range(lx):
        bef=dp[:]
        for j in range(ly): 
            # print(str(i)+" "+str(j))
            if x[i]==y[j]:
                dp[j+1]=bef[j]+1
            elif dp[j+1]<dp[j]:
                dp[j+1]=dp[j]
    print(dp[ly])

if __name__ == "__main__":
    q=int(input())
    for i in range(q):
        x=list(input())
        y=list(input())
        solve(x,y)

Python: n = int(input())

def solve(x, y):
    dp = [0] * (len(x)+1)
    for i in range(len(y)):
        yi = y[i]
        bdp = dp[:]
        for j in range(len(x)):
            xj = x[j]
            if yi == xj:
                dp[j+1] = bdp[j] + 1
            elif dp[j+1] < dp[j]:
                dp[j+1] = dp[j]

    return dp[-1]

for _ in range(n):
    x = input()
    y = input()
    print(solve(x, y))

Python: import sys

q = int(input())
for a in range(q):
    X = input()
    Y = input()
    cost = [0]
    for c in Y:
        for i in range(len(cost) - 1, -1, -1):
            index = X.find(c, cost[i]) + 1
            if index:
                if i + 1 < len(cost):
                    cost[i + 1] = min(cost[i + 1], index)
                else:
                    cost.append(index)
    print(len(cost) - 1)

Python: #!/usr/bin/python3

# main
q = int(input())
for a in range(q):
    X = input()
    Y = input()
    m = len(X)
    n = len(Y)
    c = [[0 for j in range(n + 1)] for i in range(m + 1)]
    for i in range(m + 1):
        c[i][0] = 0
    for j in range(n + 1):
        c[0][j] = 0
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if X[i - 1] == Y[j - 1]:
                c[i][j] = c[i - 1][j - 1] + 1
            else:
                c[i][j] = max(c[i][j - 1], c[i - 1][j])
    print(c[m][n])

Python: q = int(input())

def lcss(x,y):
    
    lcs = [0]*(len(x)+1)
    for i in range(len(y)):
        w1 = y[i]
        lcs_2 = lcs[:]
        for j in range(len(x)):
            if x[j] == w1:
                lcs[j+1] = lcs_2[j] + 1  
            elif lcs[j+1] < lcs[j]:
                lcs[j+1] = lcs[j]
    return lcs[-1]

ret = []
for i in range(q):
    x = input()
    y = input()
    ret.append(lcss())
print(*ret,sep= "\n")