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: Q = int(input().strip())
for q in range(Q):
    X = str(input().strip())
    Y = str(input().strip())
    lx = len(X)
    ly = len(Y)
    L = [[0 for j in range(0,ly+1)] for i in range(0,lx+1)]
    for i in range(1,lx+1):
        for j in range(1,ly+1):
            if X[i-1] == Y[j-1]:
                L[i][j] = 1 + L[i-1][j-1]
            else:
                L[i][j] = max(L[i-1][j],L[i][j-1])
    print(L[lx][ly])

Python: # Longest Common Subsequence

# 関数に入れる
def main():
    # input ← stdin.readline
    import sys
    input = sys.stdin.readline
    for _ in [0]*int(input()):
        # \n削除
        X = '_' + input()[:-1]
        Y = '_' + input()[:-1]

        lx = len(X)
        ly = len(Y)

        dp = [[0]*ly for _ in [0]*lx]

        # 変数に入れておく
        j_y = tuple(enumerate(Y))
        for i, x in enumerate(X):
            if i == 0:
                continue

            # 変数に入れておく
            dp_i = dp[i]
            dp_i1 = dp[i-1]
    
            for j, y in j_y:
                if x == y:
                    dp_i[j] = dp_i1[j-1] + 1
                else:
                    # max(a, b)を書き下す
                    a = dp_i1[j]
                    b = dp_i[j-1]
                    dp_i[j] = a if a > b else b

        print(dp[-1][-1])

if __name__ == '__main__':
    main()

Python: n = int(input())
dataset = []
for i in range(n):
    tmp = []
    tmp.append(input())
    tmp.append(input())
    dataset.append(tmp)

for data in dataset:
    m = len(data[0])
    n = len(data[1])
    i, j = 0, 0
    dp = []
    for x in range(n+1):
        dp.append([0] *(m+1))

    lcs = 0
    for j in range(n):
        for i in range(m):
            if data[0][i] == data[1][j]:
                dp[j+1][i+1] = dp[j][i] + 1
            else:
                dp[j+1][i+1] = max(dp[j+1][i], dp[j][i+1])

            #if dp[j+1][i+1] > lcs:
            #   lcs = dp[j+1][i+1]
        
    #print(lcs)
    print(dp[n][m])

Python: def lcs(X, Y):
    m, n = len(X), len(Y)
    cost = [[0] * (n+1) for _ in range(m+1)]
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if X[i - 1] == Y[j - 1]:
                cost[i][j] = cost[i - 1][j - 1] + 1
            else:
                cost[i][j] = max(cost[i][j - 1], cost[i - 1][j])
    return cost[m][n]

n = int(input())
for _ in range(n):
    X, Y = input(), input()
    print(lcs(X, Y))

Python: def lcs(X, Y):
    C = []
    for y in Y:
        bgn_idx = 0
        for i, cur_idx in enumerate(C):
            chr_idx = X.find(y, bgn_idx) + 1
            if chr_idx == 0:
                break
            C[i] = min(cur_idx, chr_idx)
            bgn_idx = cur_idx
        chr_idx = X.find(y, bgn_idx) + 1
        if chr_idx != 0:
            C.append(chr_idx)
    return len(C)

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

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: ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

def llcs(x, y):
    pm = dict((zip(ascii_letters, [0] * 52)))
    for c in pm:
        for i, xc in enumerate(x):
            if c == xc:
                pm[c] |= (1 << i)
    
    V = (1 << len(x)) - 1
    
    for yc in y:
        V = ((V + (V & pm[yc])) | (V & ~pm[yc]))
    
    ans = bin(V)[-len(x):].count('0')
    
    return ans

from sys import stdin

def solve():
    #file_input = stdin
    file_input = open("ALDS1_10_C_in_4", 'r')
    q = int(file_input.readline())
    for i in range(q):
        s1 = file_input.readline().rstrip()
        s2 = file_input.readline().rstrip()
        print(llcs(s1, s2))

solve()

Python: 
def LCS(x, y):
    dp = {}
    for i in range(len(x)+1):
        dp[i] = {0: 0}
    for j in range(len(y)+1):
        dp[0][j] = 0
    
    for i in range(1, len(x)+1):
        for j in range(1, len(y)+1):
            if x[i-1] == y[j-1]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i][j-1], dp[i-1][j])
    
    return dp[len(x)][len(y)]

q = int(raw_input())
for i in range(q):
    X = raw_input()
    Y = raw_input()
    print(LCS(X, Y))

Python: n=int(input())
x=[]
y=[]
for k in range(n):
	dp=[[0 for i in range(1000)] for j in range(1000)]
	x=list(input())
	y=list(input())
	for i in range(len(x)):
		for j in range(len(y)):
			
			if i is 0:
				if x[i] is y[j]:
					dp[i][j]=1
				else:
					dp[i][j]=dp[i][j-1]
			if j is 0:
				if x[i] is y[j]:
					dp[i][j]=1
				else:
					dp[i][j]=dp[i-1][j]

	for i in range(len(x)):
		tmp=0
		for j in range(len(y)):
			if i is not 0 and j is not 0:
				if x[i] is y[j] and tmp is 0:
					dp[i][j]=max(dp[i][j-1],dp[i-1][j])+1
					tmp+=1
				else:
					dp[i][j]=max(dp[i][j-1],dp[i-1][j])

	print(dp[len(x)-1][len(y)-1])
#	print(x,y)
#	for i in range(7):
#		print(dp[i])