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: 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])

Python: 
def main():
    n = int(input())
    for i in range(n):
        a = input()
        b = input()
        na=len(a)
        nb=len(b)
        array = [[0 for i in range(nb)] for j in range(na)]
        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: #!/usr/bin/python3
import itertools
# main
q = int(input())
for a in range(q):
    X = input()
    Y = input()
    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)
    print(len(cost) - 1)

Python: n = int(input())

for k in range(n):
    a = input()
    b = input()
    len_a, len_b = len(a), len(b)
    table = [[0] * (len_b +1) for i in range(len_a + 1)]
    
    for i in range(len_a):
        a_i = a[i]
        table_i = table[i]
        for j in range(len_b):
            if a_i == b[j]:
                table[i+1][j+1] = table_i[j] + 1
            else:
                table[i+1][j+1] = max(table_i[j+1],table[i+1][j])
    print(table[len_a][len_b])

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])