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

using namespace std;

int main(void){
    int num;
    cin>>num;
    
    vector<vector<string>> inputData(num,vector<string>(2));

    int p=0;
    while(p<num){
        for(int i=0;i<2;i++){
            cin>>inputData[p][i];
        }
        p+=1;
    }

    int q=0;
    while(q!=num){
        int s=inputData[q][0].length();
        int t=inputData[q][1].length();
        vector<vector<int>> Table(s,vector<int>(t));

        for(int i=0;i<s;i++){
            if(inputData[q][0][0]==inputData[q][1][i]){
                Table[0][i]=1;
            }else{
                Table[0][i]=0;
            }

            if(inputData[q][0][i]==inputData[q][1][0]){
                Table[i][0]=1;
            }else{
                Table[i][0]=0;
            }
        }

        vector<int> RMax(t);
        for(int i=0;i<t;i++){
            RMax[i]=Table[0][i];
        }

        //Table作成
        for(int i=1;i<s;i++){
            int max=0;
            for(int j=1;j<t;j++){
                if(RMax[j-1]>max){
                    max=RMax[j-1];
                }
                Table[i][j]=max;
                if(inputData[q][0][i]==inputData[q][1][j]){
                    Table[i][j]+=1;
                }
            }

            for(int k=0;k<t;k++){
                if(Table[i][k]>RMax[k]){
                    RMax[k]=Table[i][k];
                }
            }
        }

        //表示
        int ans=0;
        for(int i=0;i<s;i++){
            for(int j=0;j<t;j++){
                if(Table[i][j]>ans){
                    ans=Table[i][j];
                }
            }
        }

        cout<<ans<<endl;

        // for(int i=0;i<s;i++){
        //     for(int j=0;j<t;j++){
        //         cout<<Table[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }
        q+=1;
        // cout<<endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;
typedef pair<int, int> P;

#define MAX 100005
#define INF INT_MAX

string x, y;
vector < vector<int> > memo;

int lcs(int xs, int ys)
{
    if (xs == 0 || ys == 0) return 0;
    if (memo[xs][ys]) return memo[xs][ys];

    int res;
    if (x[xs-1] == y[ys-1]) {
        res = lcs(xs-1, ys-1) + 1;
    } else {
        res = max(lcs(xs,ys-1), lcs(xs-1,ys));
    }
    memo[xs][ys] = res;
    return res;
}

int main(int, char**)
{
    int q;
    cin >> q;

    vector<int> ans;
    rep(i,q) {
        cin >> x >> y;
        int xs = x.size();
        int ys = y.size();
        memo.assign(xs+1, vector<int>(ys+1,0));
        ans.push_back(lcs(xs,ys));
    }

    rep(i,q) cout << ans[i] << endl;
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

string A,B;

ll dp[1007][1007];

int LCS(string A,string B){
    REP(i,1,A.size()+1){
        REP(j,1,B.size()+1){
            if(A[i-1]==B[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[A.size()][B.size()];
}

int main(){
    ll N;cin>>N;
    rep(i,N){
        cin>>A>>B;
        cout << LCS(A,B) << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int dp[1001][1001];

int lcs(string x, string y)
{	
	int n = x.size();
	int m = y.size();

	x = " " + x;
	y = " " + y;

	for (int i = 1; i <= n; i++) dp[i][0] = 0;
	for (int j = 1; j <= m; j++) dp[0][j] = 0;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			if (x[i] == y[j]){
				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()
{
	int q;
	string s1, s2;
	cin >> q;

	for (int i = 0; i < q; i++) {		
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y) {
	int c[N + 1][N + 1];
	int m = X.size();
	int n = Y.size();
	int maxl = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	for (int i = 1; i <= m; i++)c[i][0] = 0;
	for (int j = 1; j <= n; j++)c[0][j] = 0;

	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (X[i] == Y[j]) {
				c[i][j] = c[i - 1][j - 1] + 1;
			}
			else {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}

		return maxl;
}

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

		return 0;
	}