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

C++: #include <iostream>

using namespace std;

int max_length(string x, string y)
{
    int n = x.size();
    int m = y.size();
    int dp[n+1][m+1];
    for(int i = 0; i <= m; ++i)
    {
        dp[0][i] = 0;
    }
    for(int i = 1; i <= n; ++i)
    {
        dp[i][0] = 0;
        for(int j = 1; j <= m; ++j)
        {
            if(x[i-1] == y[j-1])
            {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    return dp[n][m];
}

int main()
{
    string str1;
    string str2;
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        cin >> str1 >> str2;
        cout << max_length(str1, str2) << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int lcs(string x, string y){
    int n = x.size();
    int m = y.size();
    int dp[n+1][m+1];
    for(int i = 0;i<n+1;i++)dp[i][0] = 0;
    for(int j = 0;j<m+1;j++)dp[0][j] = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(x[i]==y[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }else{
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    return dp[n][m];
}

int main(){
    int n;cin>>n;
    // string s1,s2;
    for(int i=0;i<n;i++){
        string s1,s2;
        cin>>s1>>s2;
        cout<<lcs(s1,s2)<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>

int main(){
	int q;
	std::string a, b;
	std::vector< std::vector< int > > dp;
	
	dp.resize(1001);
	for(int i=0;i<=1000;++i){
		dp[i].resize(1001);
	}
	
	std::cin >> q;
	
	for(int i=0;i<q;++i){
		std::cin >> a >> b;
		
		for(int x=1;x<=a.length();++x){
			for(int y=1;y<=b.length();++y){
				if(a[x-1] == b[y-1]){
					dp[x][y] = std::max(std::max(dp[x - 1][y - 1] + 1, dp[x][y - 1]), dp[x - 1][y]);
				}else{
					dp[x][y] = std::max(std::max(dp[x - 1][y - 1], dp[x][y - 1]), dp[x - 1][y]);
				}
			}
		}
		std::cout << dp[a.length()][b.length()] << std::endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll q; cin >> q;
    rep(Q, q){
        string s, t; cin >> s >> t;
        ll s_size = s.size(), t_size = t.size();

        vector<vector<ll>> dp(s_size+1, vector<ll>(t_size+1));

        for(ll i = 0; i < s_size; i++){
            for(ll j = 0; j < t_size; j++){
                if(s[i] == t[j]){
                    dp[i+1][j+1] = dp[i][j] + 1;
                }else{
                    dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
                }
            }
        }

        cout << dp[s_size][t_size] << endl;

    }

}

C++: #include <iostream>
#include <cstring>
using namespace std;
char sz1[1000];
char sz2[1000];
int maxLen[1000][1000];
int main(){
int n;
cin>>n;
while( cin >> sz1 >> sz2 ){
int length1 = strlen( sz1);
int length2 = strlen( sz2);
int nTmp;
int i,j;
for( i = 0;i <= length1; i ++ )
maxLen[i][0] = 0;
for( j = 0;j <= length2; j ++ )
maxLen[0][j] = 0;
for( i = 1;i <= length1;i ++ ) {
for( j = 1; j <= length2; j ++ ){
if( sz1[i-1] == sz2[j-1] )
maxLen[i][j] = maxLen[i-1][j-1] + 1;
else
maxLen[i][j] = max(maxLen[i][j-1],maxLen[i-1][j]);
}
}
cout << maxLen[length1][length2] << endl;
n--;
if(n<1)break;
}
return 0;
}