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 <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int lcs(string a, string b) {
    vector<vector<int>> dp(a.size(), vector<int>(b.size(), 0));
    //init
    dp[0][0] = (a[0] == b[0]);
    for (auto i = 1; i < (int)a.size(); i++) dp[i][0] = dp[i - 1][0] or (a[i] == b[0]);
    for (auto i = 1; i < (int)b.size(); i++) dp[0][i] = dp[0][i - 1] or (a[0] == b[i]);
    // dp
    for (auto i = 1; i < (int)a.size(); i++) {
        for (auto j = 1; j < (int)b.size(); j++) {
            if(a[i] == b[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

//    for (auto i = 0; i < (int)b.size(); i++) {
//        for (auto j = 0; j < (int)a.size(); j++) {
//            cout << dp[j][i] << " ";
//        }
//        cout << endl;
//    }
    return dp[a.size() - 1][b.size() - 1];
}

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

    for (auto i = 0; i < q; i++) {
        string x, y; cin >> x >> y;
        cout << lcs(x, y) << endl;
    }

    return 0;
}

C++: #include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
int main(){
  int n,dp[1010][1010],i,j,k,a,b;
  scanf("%d\n",&n);
  for(k=0;k<n;k++){
    string x,y;
    cin >> x >> y;
    a=x.size(),b=y.size();
    for(i=0;i<=a;i++){
      for(j=0;j<=b;j++){
        dp[i][j]=0;
      }
    }
    for(i=1;i<=a;i++){
      for(j=1;j<=b;j++){
        if(x[i-1]==y[j-1]){
          dp[i][j]=dp[i-1][j-1]+1;
        }
        else{
          if(dp[i-1][j]>dp[i][j-1]){
            dp[i][j]=dp[i-1][j];
          }
          else{
            dp[i][j]=dp[i][j-1];
          }
        }
      }
    }
      printf("%d\n",dp[a][b]);
    }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int dp[1005][1005];
int main(){
	int q;
	cin >> q;
	rep(i,q) {
		string s, t;
		cin >> s >> t;
		int N = s.size();
		int M = t.size();
		rep(i, N) {
			rep(j, M) {
				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[N][M] << endl;
	}
	
    return 0;
}

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

using namespace std;

int solve(string s1, string s2){
    int L[s1.size()+1][s2.size()+1];
    for(int i=0;i<=s1.size();i++){
        for(int j=0;j<=s2.size();j++){
            if(i==0 || j==0){
                L[i][j]=0;
            }
            else if(s1[i] == s2[j]){
                L[i][j] = 1 + L[i-1][j-1];
            }
            else{
                L[i][j] = max(L[i][j-1],L[i-1][j]);
            }
        }
    }
    return L[s1.size()][s2.size()];
}

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

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


long long calc(int i, int j, vector<vector<long long> > &l, const string& x, const string& y){
  if(i == 0 || j == 0){
    l[i][j] = 0;
    return l[i][j];
  }
  if(l[i][j] >= 0){
    return l[i][j];
  }else{
    if(x[i-1] == y[j-1]){
      l[i][j] = 1 + calc(i-1, j-1, l, x, y);
    }else{
      l[i][j] = max(calc(i-1, j, l, x, y), calc(i, j-1, l, x, y));
    }
    return l[i][j];
  }
}
int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    string x,y;
    cin >> x >> y;
    vector<vector<long long> > l(x.length()+1, vector<long long>(y.length()+1, -1));
    cout << calc(x.length(), y.length(), l, x, y) << endl;
  }
}

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

int lcs(string s, string t){
        int a[s.size()+1][t.size()+1];
        for(int i=0;i<s.size()+1;i++) a[i][0]=0;
        for(int i=0;i<t.size()+1;i++) a[0][i]=0;
        for(int i=1;i<s.size()+1;i++){
                for(int j=1;j<t.size()+1;j++){
                        if(s[i-1]==t[j-1]) a[i][j] = a[i-1][j-1]+1;
                        else a[i][j] = max(a[i-1][j], a[i][j-1]);
                }
        }
        return a[s.size()][t.size()];
}

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

C++: // 5/5
// 2-3-2. 最長共通部分裂問題の類題

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int dp[1010][1010];

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

    int n, m;
    // cin >> n >> m;

    vector<int> ans;

    rep(p, q) {
        string s, t;
        cin >> s >> t;

        n = s.size();
        m = t.size();
        memset(dp, 0, sizeof(dp));

        dp[0][0] = 0;

        rep(i, n) {
            rep(j, m) {
                if (s[i] == t[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[n][m] << endl;
        ans.push_back(dp[n][m]);
    }

    for (auto v : ans) cout << v << endl;
}