Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

Python: for _ in range(int(input())):
    X = input()
    Y = input()
    dp = [[0 for y in range(len(Y)+1)] for x in range(len(X)+1)]
    for x in range(len(X) + 1):
        for y in range(len(Y) + 1):
            if x == 0 or y == 0:
                dp[x][y] = 0
            elif X[x-1] == Y[y-1]:
                dp[x][y] = dp[x-1][y-1] + 1
            else:
                dp[x][y] = max(dp[x-1][y], dp[x][y-1])
    print(dp[-1][-1])

Python: def lcs(X, Y):
    m = len(X)
    n = len(Y)
    c = [[0] * (n+1)] * (m+1)
    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]
    return str(c[m][n])


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

Python: def lcs(s1, s2):
    dp = []
    for s2_k in s2:
        bgn_idx = 0
        for i, cur_idx in enumerate(dp):
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if not chr_idx:
                break
            dp[i] = min(cur_idx, chr_idx)
            bgn_idx = cur_idx
        else:
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if chr_idx:
                dp.append(chr_idx)
    return len(dp)

def solve():
    N = int(input())
    for _ in range(N):
        x = input()
        y = input()
        print(lcs(x, y))

if __name__ == '__main__':
    solve()

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

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

    return dp[len(y)]


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

Python: #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main():
    num = int(stdin.readline())

    c = [range(1001) for _ in xrange(1001)]

    for _ in xrange(num):
        x = stdin.readline().rstrip()
        y = stdin.readline().rstrip()

        m = len(x)
        n = len(y)

        for i in xrange(m+1):
            row = c[i]
            for j in xrange(n+1):
                row[j] = 0

        cim1 = c[0]
        for i, xi in enumerate(x, start=1):
            ci = c[i]
            for j, yj in enumerate(y, start=1):
                if xi == yj:
                    ci[j] = cim1[j-1] + 1
                elif cim1[j] >= ci[j-1]:
                    ci[j] = cim1[j]
                else:
                    ci[j] = ci[j-1]
            cim1 = ci

        print(ci[j])


main()

Python: from sys import stdin

X = [ 0 for i in range(1000) ]
Y = [ 0 for i in range(1000) ]
Z = [[0 for i in range(1000)]for i in range(1000)]

def getLCS() :
	xlen = len(X[l])
	ylen = len(Y[l])

	for i in range(1,xlen+1) :
		for j in range(1,ylen+1) :
			if X[i-1] == Y[j-1] : Z[i][j] = Z[i-1][j-1] + 1
			elif Z[i-1][j] >= Z[i][j-1] : Z[i][j] = Z[i-1][j]
			else : Z[i][j] = Z[i][j-1]

	return Z[xlen][ylen]

n = int(input())
for l in range(n) :
	X[l] = stdin.readline().strip()
	Y[l] = stdin.readline().strip()
	print(getLCS())

Python: import sys
sys.setrecursionlimit(100000)
q = int(input())

l = []
x = ""
y = ""
def lcs(yIndex, xIndex):
    global l, x, y
    if xIndex < 0 or yIndex < 0:
        return 0
    elif x[xIndex] == y[yIndex]:
        return 1 + lcs(yIndex - 1, xIndex - 1)
    else:
        return max(lcs(yIndex, xIndex - 1), lcs(yIndex - 1, xIndex))

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

    print(lcs(len(y) - 1, len(x) - 1))

Python: """
problem statment url: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C
"""


def lcs():
	s1 = raw_input()
	s2 = raw_input()
	la, lb = len(s1), len(s2)
	dp1 = [0 for _ in range(lb + 1)]

	for i in range(la):
		dp2 = dp1 + []
		for j in range(lb):
			if s1[i] == s2[j]:
				dp1[j + 1] = dp2[j] + 1
			else:
				dp1[j + 1] = dp1[j] if dp1[j] > dp2[j + 1] else dp2[j + 1]

	return dp1[-1]

tc = int(raw_input())
for _ in range(tc):
	print(lcs())

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

Python: import sys
sys.setrecursionlimit(200000)
from collections import defaultdict
q = int(input())
for _ in range(q):
    x = input()
    y = input()
    len_x = len(x)
    len_y = len(y)
    if len_x < len_y:
        len_x, len_y = len_y, len_x
        x, y = y, x
    c = defaultdict(list)
    for i, s in enumerate(x):
        c[s].append(i)
    ans = 0
    def g(li, a):
        for i in li:
            if i >= a:
                return i
        return -1
    def f(x_i, y_i, cnt):
        if x_i >= len_x or y_i >= len_y:
            global ans
            if ans < cnt:
                ans = cnt
            return
        f(x_i, y_i + 1, cnt)
        s = g(c[y[y_i]], x_i)
        if s != -1:
            f(s + 1, y_i + 1, cnt + 1)
    f(0, 0, 0)
    print(ans)

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)