Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = dp[i-1][j-1]+1
				} else if S[i-1] != T[j-1] && dp[i-1][j] > dp[i][j-1] {
					dp[i][j] = dp[i-1][j]
				} else {
					dp[i][j] = dp[i][j-1]
				}
				// if S[i-1] == T[j-1] {
				// 	dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				// } else {
				// 	dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				// }
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}

Python: import sys
sys.setrecursionlimit(10000)
def lcs(X, Y):
    i = len(X)
    j = len(Y)
    if not i or not j:
        return 0
    if memo[i][j] >= 0:
        return memo[i][j]
    if X[-1] == Y[-1]:
        return 1 + lcs(X[:-1], Y[:-1])
    else:
        memo[i][j] = max(lcs(X[:-1], Y), lcs(X, Y[:-1]))
        return memo[i][j]

q = int(input())
for i in range(q):
    X = input()
    Y = input()
    memo = [[-1 for j in range(len(Y) + 1)] for i in range(len(X) + 1)]
    print(lcs(X, Y))

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):
        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 LCS(str1,str2):
    A = [[0 for _ in range(len(str2)+1)]for __ in range(len(str1)+1)]
    for i in range(len(str1)):
        for j in range(len(str2)):
            if(str1[i]==str2[j]):
                A[i+1][j+1] = A[i][j]+1
            elif(A[i+1][j] > A[i][j+1]):
                A[i+1][j+1] = A[i+1][j]
            else:
                A[i+1][j+1] = A[i][j+1]
    return A[-1][-1]
 
 
m = int(input())
for i in range(m):
    str1 = input()
    str2 = input()
    print(LCS(str1,str2))

Python: def solve(X, Y):
    dp = [0] * (len(Y)+1)
    for i in range(1,len(X)+1):
        tmp = 0
        for j in range(1,len(Y)+1):
            if X[i-1] == Y[j-1]:
                neo = tmp + 1
                tmp = dp[j]
                dp[j] = neo
            else:
                tmp = dp[j]
                dp[j] = max(dp[j], dp[j-1])
    return dp[len(Y)]

num = int(input())
for i in range(num):
    X = input()
    Y = input()
    print(solve(X,Y))

Python: # -*- coding: utf-8 -*-
"""
Created on Fri May  4 20:33:37 2018
ALDS1_10_C
@author: maezawa
"""

def longest(x, y):
    m = len(x)
    n = len(y)
    c = [[0 for _ in range(m+1)] for _ in range(n+1)]
    for i in range(m):
        for j in range(n):
            print(i,j)
            if x[i] == y[j]:
                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]
    return c[m-1][n-1]
                
    

q = int(input())

for i in range(q):
    x = input()
    y = input()
    
    print(longest(x, y))

Python: import sys
def lcs(X, Y):
    x = len(X) + 1
    y = len(Y) + 1
    c = [0 for y in range(y)]

    for i in X:
        tmp = c[:]
        for ji, yc in enumerate(Y):
            j = ji + 1
            if i == yc:
                c[j] = tmp[j - 1] + 1
            else:
                c[j] = max(tmp[j], c[j - 1])
    return c[y - 1]

n = int(input())

for i in range(n):
    X = sys.stdin.readline()[:-1]
    Y = sys.stdin.readline()[:-1]
    print(lcs(X, Y))

Python: """
ALDS1_10_C
最長共通部分列を二次元配列を用いた動的計画法で求める
だた，普通に二次元配列を構成するとTLEになるので工夫しなければならない
IKAPPERさんのコードを参考にしました
"""

def lcs(X, Y):
    m = len(X)
    n = len(Y)
    #xが縦，yが横
    lcs_r = [0 for _ in range(m+1)]
    for y in Y:
        previous = lcs_r[:] #copy.copy 使わなくて済むかも
        for i, x in enumerate(X):
            if x == y:
                lcs_r[i+1] = previous[i]+1
            elif lcs_r[i] > previous[i]:
                lcs_r[i+1] = lcs_r[i]
            else: #ここは省略できる（そのままpreviousがlcs_rに上がってくる）
                lcs_r[i] = previous[i] 
    
    print(lcs_r[-1])



roop = int(input())
for _ in range(roop):
    x = input()
    y = input()
    lcs(x, y)

Python: def main():
    num = int(input())
    for i in range(num):
        X = " " + input()
        Y = " " + input()
        lx = len(X)
        ly = len(Y)
        T = [0] * ly
        for j in range(1,lx):
            C = T[:]
            for k in range(1,ly):
                k1 = k-1
                if X[j] == Y[k]:
                    T[k] = C[k1] + 1
                elif C[k] > T[k1]:
                    T[k] = C[k]
                else:
                    T[k] = T[k1]
        print(T[k])

if __name__ == '__main__':
    main()

Python: import numpy as np

Python: def findlcs(x, y):
    dp = [0]*(len(y)+1)

    for c in x:
        tmp = dp[:]
        for j in range(len(y)):
            if c == y[j]:
                dp[j+1] = tmp[j] + 1
            else:
                dp[j+1] = max(dp[j+1], dp[j])

    return dp[-1]


q = int(input())
for k in range(q):
    X = input()
    Y = input()
    print(findlcs(X, Y))

Python: q = int(input())
d = [[0 for _ in range(1001)] for _ in range(1001)]
for i in range(q):
    x = input()
    y = input()
    n = len(x)
    m = len(y)
    for i in range(1001):
        d[i][0]=0
        d[0][i]=0
    for i in range(n):
        for j in range(m):
            if x[i] == y[j]:
                d[i+1][j+1] = d[i][j]+1
            else:
                d[i+1][j+1] = max(d[i+1][j],d[i][j+1])
    print(d[n][m])

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

N=int(input())
for i in range(N):
    x=input()
    y=input()
    print(lcs(x,y))