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):
    dp = {}
    for i in range(len(s) + 1):
        dp[i] = {0: 0}
    for j in range(len(t) + 1):
        dp[0][j] = 0
     
    for i in range(1,len(s)+1):
        si_1 = s[i-1]
        dpi = dp[i]
        dpi_1 = dp[i-1]
        Flag=False
        for j in range(1,len(t)+1):
            d=1 if s[i-1] == t[j-1] and dpi_1[j-1] == dp[i][j-1] else 0
            dpi[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: def lcs(X, Y):
	m = len(X)
	n = len(Y)
	c = [0 for i in range(n+1)]
	for i in range(m):
		pre_c = c[:]
		XX = X[i]
		for j in range(n):
			if XX == Y[j]:
				c[j+1] = pre_c[j] + 1
			elif c[j + 1] < c[j]:
				c[j+1] = c[j]
	return c[-1]

if __name__ == "__main__":
	q = int(input())
	for _ in range(q):
		X = input()
		Y = input()
		print(lcs(X, Y))

Python: # coding: utf-8

def lcs(str1, str2):
    # dp[i][j]: str1のi番目までとstr2のj番目までを使って作れるlcs
    dp = [[0 for _ in range(len(str2)+10)] for _ in range(len(str1)+10)]
    # 計算量は1000*1000=10^6なんだけど時間切れ？
    for i in range(0,len(str1)):
        for j in range(0,len(str2)):
            v = max(dp[i+1][j],dp[i][j+1])
            if str1[i] == str2[j]:
                dp[i+1][j+1] = max(v,dp[i][j] + 1)
            else:
                dp[i+1][j+1] = max(v,dp[i][j])
    return dp[len(str1)][len(str2)]

# てか、普通のdpじゃ通らないってどんだけシビアなんだ
def lcs_another(str1, str2):
    # str1の中の文字列とstr2の中の文字列が一致したらその位置から先を＋１するだけ
    # なんか自然には思い浮かばないなあ
    dp = [0 for _ in range(len(str2)+10)]
    for c1 in str1:
        tmp = dp[:]
        for i, c2 in enumerate(str2):
            if c1 == c2:
                dp[i+1] = tmp[i]+1
            elif dp[i+1] < dp[i]:
                dp[i+1] = dp[i]
    return dp[len(str2)]

p = int(input().rstrip())
for _ in range(p):
    line1 = input().rstrip()
    line2 = input().rstrip()
    print(lcs_another(line1,line2))

Python: MAX = 1005
n = int(input())
dp = [[0 for j in range(MAX)] for i in range(MAX)]
for _ in range(n):
    X = input()
    Y = input()
    len_X = len(X)
    len_Y = len(Y)

    for i in range(len_X):
        for j in range(len_Y):
            dp[i + 1][j + 1] = dp[i][j] + 1 if X[i] == Y[j] else max(dp[i][j + 1], dp[i + 1][j])
    print(dp[len_X][len_Y])

Python: n=int(input())

l=[]

for i in range(n):
	a=al.list(input())
	b=bl.list(input())
	dp=[[0 for i in range(len(b))] for j in range(len(a))]

	if a[0]==b[0]:
		dp[0][0]=1
	for i in range(1,len(a)):
		if a[i]==b[0]:
			dp[i][0]=1
		else:
			dp[i][0]=dp[i-1][0]
	for i in range(1,len(b)):
		if a[0]==b[i]:
			dp[0][i]=1
		else:
			dp[0][i]=dp[0][i-1]
	for i in range(1, len(a)):
		for j in range(1, len(b)):
			if a[i]==b[j]:
				dp[i][j]=dp[i-1][j-1]+1
			else:
				dp[i][j]=max(dp[i-1][j-1],dp[i-1][j],dp[i][j-1])

	l.append(dp[len(a)-1][len(b)-1])

for i in l:
	print(l)

Python: # -*- coding: utf-8 -*-
import sys
from itertools import product
sys.setrecursionlimit(100000)

N = int(input())

def calc_LCS(n, m):
    if n == 0 or m == 0:
        return 0
    elif X[n] == Y[m]:
        LCS[n][m] = LCS[n-1][m-1] + 1
        return LCS[n][m]
    else:
        LCS[n][m] = max(LCS[n-1][m], LCS[n][m-1])
        return LCS[n][m]
        

for _ in range(N):
    X = ["  "] + list(input())
    Y = [" "] + list(input())
    LCS = [[0 for _ in range(len(Y))] for _ in range(len(X))]
    max_ = 0
    for n, m in product(range(len(X)), range(len(Y))):        
        if n == 0 or m == 0:
            pass

        elif X[n] == Y[m]:
            LCS[n][m] = LCS[n-1][m-1] + 1
            
            max_ =  max(LCS[n][m], max_)
        else:
            LCS[n][m] = max(LCS[n-1][m], LCS[n][m-1])
            max_ = max(LCS[n][m], max_)
    print(max_)

Python: import sys

def dp_init(m, n):
    return [[0] * n] * m

def solve(str_a, str_b):
    dp = dp_init(len(str_a), len(str_b))
    return rec(len(str_a), len(str_b), str_a, str_b, dp)

def rec(i, j, str_a, str_b, dp):
    if i == 0 or j == 0:
        return 0
    if dp[i-1][j-1] > 0:
        return dp[i-1][j-1]
    if str_a[i-1] == str_b[j-1]:
        dp[i-1][j-1] = rec(i-1, j-1, str_a, str_b, dp) + 1
        return dp[i-1][j-1]
    dp[i-1][j-1] = max(rec(i, j-1, str_a, str_b, dp), rec(i-1, j, str_a, str_b, dp))
    return dp[i-1][j-1]

nb_pairs = int(input())
pairs = []
for i in range(0, nb_pairs):
    pairs.append((input(), input()))

for i in range(0, nb_pairs):
    str_a, str_b = pairs[i]
    print(solve(str_a, str_b))

Python: def Ics(x, y):
    a = len(x)
    b = len(y)
    c1 = [0] * (b + 1)

    for i in range(a):
        d = x[i]
        c2 = c1[:]
        for j in range(b):
            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())
r = []
for k in range(q):
    s1 = input().rstrip()
    s2 = input().rstrip()
    r.append(Ics(s1, s2))

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

Python: def common():
   X = raw_input()
   Y = raw_input()
 
   s = [0 for i in range(len(Y)+1)]

   for j in range(0, len(X)):
      t = s + []
      for k in range(0, len(Y)):
         if X[j] == Y[k]:
            s[k+1] = t[k] + 1
         elif s[k+1] < s[k]:
            s[k+1] = s[k]
 
   return s[-1]

q = input()
for l in range(0, q):
   common()