Go: package main

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

var (
	nstr   func() string
	stdout *bufio.Writer
)

func init() {
	nstr = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func main() {
	defer stdout.Flush()

	n := nint()
	xList := make([]string, n)
	yList := make([]string, n)

	for i:=0;i<n ;i++  {
		xList[i] = nstr()
		yList[i] = nstr()
	}

	for i := 0; i<n	; i++  {
		fmt.Println(lcs(xList[i], yList[i]))
	}

}

func lcs(x string, y string) int{
	var m = len(x)
	var n = len(y)

	c := make([][]int, m+1)
	for i:= range c{
		c[i] = make([]int, n+1)
	}
	for i:=	1;i<=m ;i++  {
		for j:=1;j<=n ;j++  {
			if x[i-1] == y[j-1]{
				c[i][j] = c[i-1][j-1] + 1
			}else{
				c[i][j] = int(math.Max(float64(c[i-1][j]), float64(c[i][j-1])))
			}


		}
	}
	return c[m][n]

}


func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func nint64() int64 {
	i, err := strconv.ParseInt(nstr(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func nint() int {
	return int(nint64())
}

func getIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nint()
	}
	return b
}

func getStringSlice(n int) []string {
	b := make([]string, n)
	for i := 0; i < n; i++ {
		b[i] = nstr()
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func bin(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0b" + strconv.FormatInt(i64, 2)
	} else {
		return strconv.FormatInt(i64, 2)
	}
}

func strReverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

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: import sys

def lcm(c,i, j):
    if c[i][j]>0: return c[i][j]        
    if i==0 or j==0:
        return 0
    elif x[i]==y[j]:
        c[i][j] = lcm(c,i-1,j-1)+1
        return c[i][j]
    else:
        c[i][j] = max(lcm(c,i,j-1), lcm(c,i-1,j))
        return c[i][j]

for _ in range(int(sys.stdin.readline())):
    x = sys.stdin.readline()
    y = sys.stdin.readline()
    c = [[0 for _ in range(len(x)+2)] for _ in range(len(y)+2)] 
    print(lcm(c,len(x)-1,len(y)-1))

Python: q = int(input())
ans = []
for _ in range(q):
    x = input()
    y = input()
    m = len(x)
    n = len(y)
    c = [0] * (n + 1)
    for i in range(m):
        tmp = x[i]
        c_ = c[:]
        for j in range(n):
            if tmp == y[j]:
                c[j + 1] = c_[j] + 1
            elif c[j + 1] < c[j]:
                c[j + 1] = c[j]
    ans.append(c[-1])

print(*ans, sep="\n")