Go: package main

/*
最長共通部分列
*/

import (
	"bufio"
	"bytes"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func larger(l, r int) int {
	if l > r {
		return l
	}
	return r
}

var memo [1001][1001]int

func countLCS(x, y string) int {
	x = " " + x
	y = " " + y
	max := 0
	for xi := 1; xi < len(x); xi++ {
		for yi := 1; yi < len(y); yi++ {
			if x[xi] == y[yi] {
				memo[xi][yi] = memo[xi-1][yi-1] + 1
			} else {
				memo[xi][yi] = larger(memo[xi-1][yi], memo[xi][yi-1])
			}
			max = larger(max, memo[xi][yi])
		}
	}
	return max
}

func main() {
	scanner := makeScanner(1024)
	q := eGetInt(scanner)
	for i := 0; i < q; i++ {
		x := eGetLine(scanner)
		y := eGetLine(scanner)
		fmt.Println(countLCS(x, y))
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	buf.WriteString("[")
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = ", "
	}
	buf.WriteString("]")
	return buf.String()
}

func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}
func max(a ints) (int, bool) {
	if len(a) == 0 {
		return 0, false
	}
	m := a[0]
	for _, e := range a {
		if e > m {
			m = e
		}
	}
	return m, true
}
func min(a []int) int {
	m := a[0]
	for _, v := range a {
		if v < m {
			m = v
		}
	}
	return m
}

func sum(a ints) int {
	if len(a) == 0 {
		return 0
	}
	sum := 0
	for _, e := range a {
		sum += e
	}
	return sum
}
func find(n int, a ints) int {
	for i, v := range a {
		if n == v {
			return i
		}
	}
	return -1
}

C++: #include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;



class LCS{
    public:
    long long int **dp;
    long long int **longest;
    long long int result;
    string LCSstr;
    LCS(long long int one,long long int two){
        dp=new long long int*[one];
        longest=new long long int *[one];
        for(int i=0;i<one;i++){
            dp[i]=new long long int[two];
            longest[i]=new long long int[two];
        } 
    }
    void DoLCS(string str1,string str2){
        LCSstr.clear();
        for(int i=0;i<str1.length();i++){
            for(int j=0;j<str2.length();j++){
                dp[i][j]=0;
                longest[i][j]=0;
            }
            
        }

        for(int i=0;i<str1.length();i++){
            if(str1[i]==str2[0]){dp[i][0]=1;}
            else{dp[i][0]=0;}
            for(int j=1;j<str2.length();j++){
                if(i!=0)dp[i][j]=longest[i-1][j-1];
                if(str1[i]==str2[j]){dp[i][j]++;}
            }
            
            if(i!=0){
                longest[i][0]=max({longest[i-1][0],dp[i][0]});
                for(int j=1;j<str2.length();j++){
                    longest[i][j]=max({longest[i-1][j],dp[i][j],longest[i][j-1]});
                }
            }else{
                longest[0][0]=dp[i][0];
                for(int j=1;j<str2.length();j++){
                    longest[0][j]=max({dp[0][j],longest[0][j-1]});
                }
            }
        }

        pair<long long int ,long long int>rev;
        rev={str1.length(),str2.length()};
        long long int now=longest[str1.length()-1][str2.length()-1];
        bool key=false;
        //cout<<now<<endl;
        //DEBUG_OUTPUT_ARRAY2_BOX(dp,rev.first,rev.second);
        while(now!=0){
            key=false;
            for(int j=0;j<rev.first;j++){
                if(now==dp[j][rev.second-1]&&(now-1==longest[max(j-1,0)][max(rev.second-1-1,0LL)]||j==0||rev.second-1==0)){
                    
                    LCSstr.push_back(str1[j]);
                    rev={j,rev.second-1};
                    now--;
                    key=true;
                    //cout<<"REV>>"<<rev.first<<" "<<rev.second<<endl;
                    break;
                }
            }
            if(key){continue;}
            for(int j=0;j<rev.second;j++){
                if(now==dp[rev.first-1][j]&&(now-1==longest[max(rev.first-1-1,0LL)][max(j-1,0)]||rev.first-1==0||j==0)){
                    now--;
                    LCSstr.push_back(str2[j]);
                    rev={rev.first-1,j};
                    key=true;
                    
                    //cout<<"REV>>"<<rev.first<<" "<<rev.second<<endl;
                    break;
                }
            }
            if(!key){
                rev={rev.first-1,rev.second-1};
            }        
        }
        reverse(LCSstr.begin(),LCSstr.end());
        result=LCSstr.length();
    }
    ~LCS(){}
};

long long int N,M,W,dp[55000]={},c[10005],w[105];
string str[350],str2[350];

int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    
    LCS lcs(1005,1005);
    for(long long int i = 1; i <= N; i++){
        cin>>str[i]>>str2[i];
        

        lcs.DoLCS(str[i],str2[i]);
        cout<<lcs.LCSstr.length()<<endl;
        
    }
     
        
        
    
    
}