Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = dp[i-1][j-1]+1
				} else if S[i-1] != T[j-1] && dp[i-1][j] > dp[i][j-1] {
					dp[i][j] = dp[i-1][j]
				} else {
					dp[i][j] = dp[i][j-1]
				}
				// if S[i-1] == T[j-1] {
				// 	dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				// } else {
				// 	dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				// }
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}

Python: def lcs(s1, s2):
    dp = []
    for s2_k in s2:
        bgn_idx = 0
        for i, cur_idx in enumerate(dp):
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if not chr_idx:
                break
            dp[i] = min(cur_idx, chr_idx)
            bgn_idx = cur_idx
        else:
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if chr_idx:
                dp.append(chr_idx)
    return len(dp)

n = int(input())
ans = []
for _ in range(n):
    x = input()
    y = input()
    ans.append(lcs(x, y))

for i in ans:
    print(i)

Python: def len_LCS(X,Y):
    Z = X
    if len(X) > len(Y): Z,Y = Y,X
    D = {}
    def len_LCS_core(Z,Y):
        if Z in D: return D[Z]
        if Z in Y:
            D[Z] = len(Z)
            return D[Z]
        D[Z] = 0
        if len(Z) < 2: return 0
        for i in range(len(Z)):
            D[Z] = max(D[Z], len_LCS_core(Z[:i]+Z[i+1:],Y))
        return D[Z]
    return len_LCS_core(Z,Y)
        
if __name__=='__main__':
    n = int(input())
    for _ in range(n):
        X = input()
        Y = input()
        print(len_LCS(X,Y))

Python: if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    N = 1000

    def lcs(X, Y):
        c = [[0]*(N+1) for _ in range(N+1)]
        maxl = 0
        X = ' ' + X # 1オリジンにする
        Y = ' ' + Y
        pre_row = c[0]
        for i, x in enumerate(X):
            if i == 0:
                continue
            row = c[i]
            for j, y in enumerate(Y):
                if j == 0:
                    continue
                if x == y:
                    value = pre_row[j-1] + 1
                    row[j] = value
                    if maxl < value: # maxlの更新はこの時しか起こらない
                        maxl = value
                else:
                    pre_row_j = pre_row[j]
                    row_j_1 = row[j-1]
                    value = row_j_1
                    if pre_row_j > row_j_1:
                        value = pre_row_j # max関数だと、とても遅い
                    row[j] = value
            pre_row = row # 今の列が次の列にとって一つ前の列になる

        return maxl

    n = int(input())
    for _ in range(n):
        s1 = input()[:-1]
        s2 = input()[:-1]
        print(lcs(s1, s2))

Python: def Ics(X, Y):
    m = len(X)
    n = len(Y)
    c1 = [0] * (n + 1)
    c2 = [0] * (n + 1)
    for i in range(m):
        d = X[i]
    for j in range(n):
        if (d == Y[j]):
            c1[j + 1] = c2[j] + 1
        elif (c1[j + 1] < c1[j]):
            c1[j + 1] = c1[j]
    return (c1[-1])

q = int(input().rstrip())
t = []
for i in range(q):
    s1 = input().rstrip()
    s2 = input().rstrip()
    t.append(Ics(s1, s2))
print(*t, sep="\n")

Python: from sys import stdin
input = stdin.readline

N = 1000

def lcs(X, Y):
    c = [[0]*(N+1) for _ in range(N+1)]
    maxl = 0
    X = ' ' + X # 1オリジンにする
    Y = ' ' + Y
    pre_row = c[0]
    for i, x in enumerate(X):
        if i == 0:
            continue
        row = c[i]
        for j, y in enumerate(Y):
            if j == 0:
                continue
            if x == y:
                value = pre_row[j-1] + 1
                row[j] = value
                if maxl < value: # maxlの更新はこの時しか起こらない
                    maxl = value
            else:
                pre_row_j = pre_row[j]
                row_j_1 = row[j-1]
                value = row_j_1
                if pre_row_j > row_j_1:
                    value = pre_row_j # max関数だと、とても遅い
                row[j] = value
        pre_row = row # 今の列が次の列にとって一つ前の列になる

    return maxl

n = int(input())
for _ in range(n):
    s1 = input()[:-1]
    s2 = input()[:-1]
    print(lcs(s1, s2))

Python: def len_LCS(X,Y):
    x_l = len(X)
    y_l = len(Y)
    lcs_row = [0 for _ in range(x_l+1)]
    for yc in Y:
        lcs_row_p = lcs_row[:]
        # lcs_row_p: [i] [i+1]
        # lcs_row  : [i] [i+1]
        for i in range(x_l):
            if X[i] == yc:
                lcs_row[i+1] = lcs_row_p[i] + 1
            elif lcs_row[i] > lcs_row_p[i+1]:
                lcs_row[i+1] = lcs_row[i]
    return lcs_row[-1]
        
if __name__=='__main__':
    n = int(input())
    for _ in range(n):
        X = input()
        Y = input()
        print(len_LCS(X,Y))

Python: import sys
sys.setrecursionlimit(200000)
from collections import defaultdict
from bisect import bisect_left, bisect, insort_left, insort
q = int(input())
for _ in range(q):
    x = input()
    y = input()
    len_x = len(x)
    len_y = len(y)
    if len_x < len_y:
        len_x, len_y = len_y, len_x
        x, y = y, x
    c = defaultdict(list)
    for i, s in enumerate(x):
        c[s].append(i)
    ans = 0
    def f(x_i, y_i, cnt):
        if x_i >= len_x or y_i >= len_y:
            global ans
            if ans < cnt:
                ans = cnt
            return
        f(x_i, y_i + 1, cnt)
        s = bisect_left(c[y[y_i]], x_i)
        if s < len(c[y[y_i]]) and c[y[y_i]][s] < len_x:
            f(c[y[y_i]][s] + 1, y_i + 1, cnt + 1)
    f(0, 0, 0)
    print(ans)

Python: def ask(X,Y):

 a=len(X)
 b=len(Y)
 Z=[]
 for n in range(a):
  z=0
  c=0
  for i in range(n,a):
   for j in range(c,b):
    if(c==b-1):
     break
    if(X[i]==Y[j]):
     z+=1
     c=j
     break
     
  Z.append(z)

 Z.sort();
 return Z[a-1]


q=int(input())
Z=[]
for p in range(q):
 x=input()
 X=list(x)
 y=input()
 Y=list(y)
 z=ask(X,Y)
 Z.append(z)

for p in range(q):
 print(Z[p])