Go: package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

Python: 
def main():
    n = int(input())
    for i in range(n):
        a = input()
        b = input()
        na=len(a)
        nb=len(b)
        array = [[0]*nb]*na
        #array = [[0 for i in range(nb)] for j in range(na)]
        print(array)
        for i in range(na):
            for j in range(nb):
                if i==0:
                    if a[i]==b[j]:
                        array[i][j]=1
                elif j==0:
                    if a[i]==b[j]:
                        array[i][j]=1
                else:
                    c = 0
                    if a[i] == b[j]:
                        c = 1
                    array[i][j] = array[i-1][j-1]+c 
                    max(
                            array[i-1][j],
                            array[i][j-1],
                            array[i-1][j-1]+c)
        print(array[na-1][nb-1])
if __name__ == "__main__":
    main()

Python: import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def lcs(X, Y):
    dp = []
    for y in Y:
        bgn_idx = 0
        for i, cur_idx in enumerate(dp):
            # 既に探索済みの最長文字列を更新
            chr_idx = X.find(y, bgn_idx) + 1
            if not chr_idx:
                break
            dp[i] = min(chr_idx, cur_idx)
            bgn_idx = cur_idx
        else:
            chr_idx = X.find(y, bgn_idx) + 1
            if chr_idx:
                dp.append(chr_idx)
    return len(dp)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    for _ in range(N):
        X, Y = iss(), iss()
        print(lcs(X, Y))


if __name__ == '__main__':
    main()

Python: #coding:utf-8
from copy import deepcopy
import numpy as np
n = int(input())

def lcs(X,Y):
    m = len(X)
    n = len(Y)
    c = [[False for i in range(n+1)] for j in range(m+1)]
    for i in range(m+1):
        c[i][0] = 0
    for i in range(n+1):
        c[0][i] = 0
    for i in range(1,m+1):
        for j in range(1,n+1):
            if X[i-1] == Y[j-1]:
                c[i][j] = c[i-1][j-1] + 1
            elif c[i-1][j] >= c[i][j-1]:
                c[i][j] = c[i-1][j]
            else:
                c[i][j] = c[i][j-1]
    c = np.array(c)
    return c[m][n]
                            
        
for  i in range(n):
    A = input()
    B = input()
    a = lcs(A,B)
    print(a)

Python: def longest_common(x, y):
    cost = [0]
    for c in y:
        for i in range(len(cost) -1, -1, -1):
            index = x.find(c, cost[i]) + 1
            if index:
                if i + 1 < len(cost):
                    cost[i + 1] = min(cost[i + 1], index)
                else:
                    cost.append(index)
    return len(cost)  - 1
            

n = int(input())
for _ in range(n):
    x = input()
    y = input()
    print(longest_common(x, y))

Python: a=''
for _ in[0]*int(input()):
 X,z=input(),[]
 for y in input():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 a+=f'\n{len(z)}'
print(a[1:])

Python: def lcs(X,Y):
    f=[[0 for i in range(len(Y)+1)]for j in range(len(X)+1)]
    for i in range(len(X)):
        for j in range(len(Y)):
            if X[i]==Y[j]:
                f[i+1][j+1]=f[i][j]+1
            else:
                f[i+1][j+1]=max(f[i][j+1],f[i+1][j])
    return f[len(X)][len(Y)]

q=int(input())
A=[0 for i in range(q)]
for i in range(q):
    X=input()
    Y=input()
    A[i]=lcs(X,Y)

for i in range(q):
    print(A[i])

Python: a=[]
for _ in[0]*int(input()):
 X,z=input(),[]
 for y in input():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 a+=[len(z)]
print(*a,sep='\n')

Python: def lcs(X,Y,p,q,Z):
    for i in range(p):
        for j in range(q):
            if X[i]==Y[j]:
                Z[i+1][j+1]=Z[i][j]+1
            else:
                if Z[i][j+1]>Z[i+1][j]:
                    Z[i+1][j+1]=Z[i][j+1]
                else:
                    Z[i+1][j+1]=Z[i+1][j]
    print(Z[p][q])

n=int(input())
for i in range(n):
    X=input()
    Y=input()
    p=len(X)
    q=len(Y)
    Z=[[0 for i in range(q+1)]for j in range(p+1)]
    lcs(X,Y,p,q,Z)

Python: n=int(input())
al=[]
bl=[]
for i in range(n):
	al.append(list(input()))
	bl.append(list(input()))

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

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

			elif a[i]!=b[j]:
				dp[i][j]=max(dp[i-1][j-1],dp[i-1][j],dp[i][j-1])
			else:
				dp[i][j]=dp[i-1][j-1]+1

	print(dp[len(a)-1][len(b)-1])

Python: def lcs(X, Y):
    a = len(X)
    b = len(Y)
    c1 = [0] * (b + 1)
    for i in range(a):
        e1 = X[i]
        c2 = c1[:]
        for j in range(b):
            if e1 == Y[j]:
                c1[j+1] = c2[j] + 1
            elif c1[j+1] < c1[j]:
                c1[j+1] = c1[j]
    return c1[-1]

n = int(input().rstrip())
ret = []
for i in range(n):
    s1 = input()
    s2 = input()
    ret.append(lcs(s1, s2))
print(*ret, sep = '\n')