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: 
def main():
    n = int(input())
    for i in range(n):
        a = input()
        b = input()
        array = [[0 for i in range(len(b))] for j in range(len(a))]
        """
        for i in range(len(a)):
            if a[i]==b[0]:
                array[i][0]=1
        for j in range(len(b)):
            if b[j]==a[0]:
                array[0][j]=1 
        """
        for i in range(len(a)):
            for j in range(len(b)):
                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] = max(
                                        array[i-1][j],
                                        array[i][j-1],
                                        array[i-1][j-1]+c)
        print(array[len(a)-1][len(b)-1])
        #p.pprint(array)
if __name__ == "__main__":
    main()

Python: def lcs_len(x, y):
    ly = len(y)
    tcsl = [0] * (ly + 1)
    for x_i in x:
        pre_tcsl = list(tcsl)
        for j in range(ly):
            if x_i == y[j]:
                tcsl[j] = pre_tcsl[j - 1] + 1
            else:
                tcsl[j] = max(pre_tcsl[j], tcsl[j - 1])
    print(tcsl[j])


q = int(input())

for i in range(q):
    ax = input()
    ay = input()
    lcs_len(ax, ay)

Python: 
def LCS(x, y):
    len_x = len(x)
    len_y = len(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: q=int(input())

def lastindex(a,x):
    try:
        return len(a)-a[::-1].index(x)-2
    except:
        return(-1)
for repeat in range(q):
    X=input()
    Y=input()
    lenX=len(X)
    lenY=len(Y)
    Z=[[0 for i in range(lenY)] for i in range(lenX)]

    if X[0]==Y[0]:
        Z[0][0]=1
    
    for i in range(1,lenY):
        if Z[0][i-1]==1:
            Z[0][i]=1
        else:
            if Y[i]==X[0]:
                Z[0][i]=1

    for j in range(lenX):
        if Z[j-1][0]==1:
            Z[j][0]=1
        else:
            if X[j]==Y[0]:
                Z[j][0]=1


    for i in range(1,lenX):
        for j in range(1,lenY):
            x=lastindex(X[:i+1:],Y[j])
            y=lastindex(Y[:j+1:],X[i])

            if x!=-1 and y!=-1:
                Z[i][j]=max(Z[x][j],Z[i][y])+1
            elif x!=-1:
                Z[i][j]=Z[x][j]+1
            elif y!=-1:
                Z[i][j]=Z[i][y]+1

            Z[i][j]=max(Z[i][j],Z[i-1][j],Z[i][j-1])

    print(Z[-1][-1])

Python: import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)


q = int(input())
for _ in range(q):
    s = input()
    t = input()

    info = deque(deque() for _ in range(100))
    check = []
    for i in range(len(s)):
        info[ord(s[i]) - 97].appendleft(i)
    ans = [INF] * (max(len(s), len(t)) + 10)
    link = [0] * (max(len(s), len(t)) + 10)
    for i in t:
        for l in info[ord(i) - 97]:
            ans[bisect_left(ans, l)] = l
    print(bisect_left(ans, INF))

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def lcs(A, B):
    m, n = len(A), len(B)
    count_list = [[0] * (n + 1) for _ in range(m + 1)]

    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if A[i - 1] == B[j - 1]:
                count_list[i][j] = count_list[i - 1][j - 1] + 1
            elif count_list[i - 1][j] >= count_list[i][j - 1]:
                count_list[i][j] = count_list[i - 1][j]
            else:
                count_list[i][j] = count_list[i][j - 1]

    return count_list[m][n]


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    pair_num = int(_input[0])

    word_list = list(map(lambda x: x.strip(), _input[1:]))
    # assert len(word_list) == 2 * pair_num
    for k in range(0, len(word_list), 2):
        print(lcs(word_list[k], word_list[k + 1]))

Python: def ask(X,Y):
 cost=[0]
 for j in Y:
  for i in range(len(cost)-1,-1,-1):
   a=X.find(j,cost[i])+1
   if a:
    if i+1<len(cost):
     cost[i+1]=min(cost[i+1],a)
    else:
     cost.append(a)
 return len(cost)-1
 


q=int(input())
Z=[]
for p in range(q):
 X=input()
 Y=input()
 z=ask(X,Y)
 Z.append(z)

for p in range(q):
 print(Z[p])