Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

Python: def num_substr(s, t):
    sl = len(s)
    tl = len(t)
    dp = {}
    for i in range(sl + 1):
        dp[i] = {0: 0}
    for j in range(sl + 1):
        dp[0][j] = 0
     
    for i in range(1,sl+1):
        si_1 = s[i-1]
        dpi = dp[i]
        dpi_1 = dp[i-1]
        for j in range(1,tl+1):
            d=1 if si_1 == t[j-1] and dpi_1[j-1] == dpi[j-1] else 0
            dp[i][j] = max(dpi_1[j] ,
                           dpi[j-1] +d)
    return dp[len(s)][len(t)]
 
n = int(input())
for i in range(n):
    s = input()
    t = input()
    print(num_substr(s,t))

Python: for _ in range(int(input())):
    x = list(input())
    y = list(input())
    dp = [[0] * (len(y) + 1) for i in range(len(x) + 1)]
    for i in range(len(x)):
        for j in range(len(y)):
            if x[i] == y[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
    print(dp[-1][-1])

Python: def lcs_len(X,Y):
    m,n=len(X),len(Y)
    LCS=[0 for _ in range(m+1)]
    for y in Y:
        previous=LCS[:]
        for i,x in enumerate(X):
            if x==y:
                LCS[i+1]=previous[i]+1
            elif LCS[i]>previous[i+1]:
                LCS[i+1]=LCS[i]
    return LCS[-1]

q=int(input())
for _ in range(q):
    X=list(input())
    Y=list(input())
    print(lcs_len(X,Y))

Python: m = int(input())
for i in range(m):
    str1 = input()
    str2 = input()
    A = [[0 for j in range(len(str1)+1)]for k in range(len(str2)+1)]
    for j in range(len(str2)):
        for k in range(len(str1)):
            if(str1[k]==str2[j]):
                A[j+1][k+1] = A[j][k]+1
            else:
                if(A[j+1][k] < A[j][k+1]):
                    A[j+1][k+1] = A[j][k+1]
                else:
                    A[j+1][k+1] = A[j+1][k]
    print(A[len(str2)][len(str1)])

Python: # coding: utf-8

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]


def solve():
    x = input().strip()
    y = input().strip()

    # dp[i][j]: x[:i], y[:j] ???LCS
    # dp[i][j] = max(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]+1(if x[i]==y[j]))
    dp = array2d(len(x), len(y), 0)
    dp[0][0] = int(x[0] == y[0])
    for j in range(1, len(y)):
        dp[0][j] = max(dp[0][j-1], int(x[0] == y[j]))
    for i in range(1, len(x)):
        dp[i][0] = max(dp[i-1][0], int(x[i] == y[0]))
        for j in range(1, len(y)):
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
            if x[i] == y[j]:
                dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1)
    return dp[-1][-1]


def main():
    cases = int(input())
    for i in range(cases):
        print(solve())

main()

Python: query = int(input())
for _ in range(query):
    A = input().strip()
    B = input().strip()
    dp = [[0 for n in range(len(A) + 1)] for m in range(len(B) + 1)]
    for i in range(len(B) + 1):
        for inner in range(len(A) + 1):
            if i == 0:
                continue
            elif inner == 0:
                choice = dp[i - 1][inner]
            else:
                choice = max(dp[i][inner - 1], dp[i - 1][inner], dp[i - 1][inner - 1] + int(A[inner - 1] == B[i - 1]))
            dp[i][inner] = choice
#                 print(i, inner, A[inner - 1], B[i - 1])
#         print(dp)
    print(dp[len(B)][len(A)])

Python: import sys


def lcs(x, y):
    # Creating len(x + 1) * len(y + 1) table
    x = ' ' + x  # Add Space
    y = ' ' + y  # Add Space
    len_x = len(x)
    len_y = len(y)
    table = []
    for _ in range(len_y):
        table.append([0] * len_x)

    maxl = 0
    for i, x_ch in enumerate(x):
        if i == 0: continue
        for j, y_ch in enumerate(y):
            if j == 0: continue
            if x[i] == y[j]:
                table[j][i] = table[j - 1][i - 1] + 1
            else:
                table[j][i] = max(table[j - 1][i], table[j][i - 1])
            maxl = max(maxl, table[j][i])

    return maxl


if __name__ == "__main__":
    lines = [line.strip() for line in sys.stdin.readlines()[1:]]
    for sequence_pair in zip(lines[::2], lines[1::2]):
        print(lcs(*sequence_pair))