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>
#include <vector>
#include <string>
#include <algorithm>

int lcs(std::string str1, std::string str2) {
    std::vector<std::vector<int> > table(str1.size(), std::vector<int>(str2.size(), 0));
    // Initialization
    for (int i=0; i<str1.size(); i++) {
        if ( str1[i] == str2[0] ) {
            table[i][0] = 1;
        } else {
            table[i][0] = 0;
        }
    }
    for (int j=0; j<str2.size(); j++) {
        if ( str2[j] == str1[0] ) {
            table[0][j] = 1;
        } else {
            table[0][j] = 0;
        }
    }
    // Calculate LCS
    for (int i=1; i<str1.size(); i++) {
        for (int j=1; j<str2.size(); j++) {
            table[i][j] = std::max( table[i-1][j], table[i][j-1] );
            if ( str1[i] == str2[j] ) {
                table[i][j]++;
            }
        }
    }
    return table[str1.size()-1][str2.size()-1];
}

int main() {
    int n;
    std::cin >> n;
    std::string str1, str2;
    std::vector<int> res(n);
    for (int i=0; i<n; i++) {
        std::cin >> str1 >> str2;
        res[i] = lcs(str1, str2); 
    }
    for (int i=0; i<n; i++) {
        std::cout << res[i] << std::endl;
    }
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int LCS[1010][1010];

void solve(string x, string y)
{
	for (int i = 0; i != x.size(); i++)
	{
		for (int j = 0; j != y.size(); j++)
		{
			if (x[i] == y[j])
			{
				LCS[i + 1][j + 1] = LCS[i][j] + 1;
			}
			else
			{
				LCS[i + 1][j + 1] = max(LCS[i][j + 1], LCS[i + 1][j]);
			}
		}
	}

	cout << LCS[x.size()][y.size()] << endl;
}

int main()
{
	int q;
	cin >> q;

	for (int i = 0; i < 1000; i++)
	{
		LCS[0][i] = 0;
		LCS[i][0] = 0;
	}

	for (int i = 0; i < q; i++)
	{
		string x, y;
		cin >> x >> y;
		solve(x, y);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int	lcs(const string &X, const string &Y)
{
	int	len_X = X.size(), len_Y = Y.size();
	int	len_lcs[1001][1001] = {};
	for (int i = 0; i < len_X; ++i) {
		for (int j = 0; j < len_Y; ++j) {
			int	prev_X = len_lcs[i][j + 1];
			int	prev_Y = len_lcs[i + 1][j];
			int	prev = max(prev_X, prev_Y);	
			if (X.at(i) == Y.at(j)) {
				len_lcs[i + 1][j + 1] = max(len_lcs[i][j] + 1, prev);
			} else {
				len_lcs[i + 1][j + 1] = prev;
			}
		}
	}
	return len_lcs[len_X][len_Y];
}

int	main()
{
	int	q;
	cin >> q;
	string	X, Y;
	for (int i = 0; i < q; ++i) {
		cin >> X >> Y;
		cout << lcs(X, Y) << endl;
	}
}

C++: #include<iostream>
using namespace std;
/*int lcs(string a,string b)
{
    if(a.length()<=0||b.length()<=0)
    {
        return 0;
    }
    else if(a[a.length()-1]==b[b.length()-1])
    {
        return 1+lcs(a.substr(0,a.length()-1),b.substr(0,b.length()-1));
    }
    else
    {
        return max(lcs(a.substr(0,a.length()),b.substr(0,b.length()-1)),lcs(a.substr(0,a.length()-1),b.substr(0,b.length())));
    }
};*/
int main()
{
    int num;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        int lcs[1001][1001]={};
        string a,b;
        cin>>a>>b;
        //cout<<lcs(a,b)<<endl;
        for(int i=0;i<a.length()+1;i++)
        {
            for(int j=0;j<b.length()+1;j++)
            {
                if(i==0||j==0)
                {
                    lcs[i][j]=0;
                }
                else if(a[i]==b[j])
                {
                    lcs[i][j]=lcs[i-1][j-1]+1;
                }
                else
                {
                    lcs[i][j]=max(lcs[i][j-1],lcs[i-1][j]);
                }
            }
        }
        cout<<lcs[a.length()][b.length()]<<endl;
    }
}

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

int dp[1002][1002] = { 0 };

int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		string x, y;
		int cnt = 0;
		cin >> x >> y;
		memset(dp, 0, sizeof(dp));

		for (int j = 1; j <= x.size(); ++j) {
			for (int j2 = 1; j2 <= y.size(); ++j2) {
				if (x[j - 1] == y[j2 - 1]) {
					dp[j][j2] = max(dp[j][j2 - 1], dp[j - 1][j2 - 1] + 1);
				}
				else {
					dp[j][j2] = max(dp[j][j2 - 1], dp[j - 1][j2]);
				}
			}
		}
		cout << dp[x.size()][y.size()] << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
        int q;
        scanf("%d",&q);
        while(q--){
                string str1,str2;
                cin >> str1 >> str2;
                vector<vector<int>> dp(str1.size()+1,vector<int>(str2.size()+1,0));
                for(int i = 0; i < str1.size(); i++){
                        for(int j = 0; j < str2.size(); j++){
                                if(str1[i] == str2[j]){
                                        dp[i+1][j+1] = dp[i][j] + 1;
                                }else{
                                        dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
                                }
                        }
                }
                cout << dp[str1.size()][str2.size()] << endl;
        }
        return 0;
}