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;

constexpr int max_len = 1024;

int lcs(const string &s,const string &t){
    const int m=s.size(),n=t.size();
    vector<vector<int>> dp(m+1,vector<int>(n+1,0));

    for(int i=0;i<m;i++){
        for(int j=0;j<n;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]);
        }
    }

    return dp[m][n];
}

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

C++: #include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;
int main() {
    int query;
    cin >> query;
    for(int q=0;q<query;q++){
        string x,y;
        cin >> x >> y;
        vector<vector<int> > dp(x.length()+1,vector<int>(y.length()+1,0));
        for(int i=0;i<x.length();i++){
            for(int j=0;j<y.length();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]);
                }
            }
        }
        cout << dp[x.length()][y.length()] << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e9+7;
const ll N = 1002;
const ll M = 21;
ll q,dp[N][N];
string x,y;
vector <ll> ans;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>q;
	FOR(k,0,q){
		cin>>x>>y;
		FOR(i,0,x.size()+1){
			FOR(j,0,y.size()+1){
				dp[i][j]=0;
			}
		}
		FOR(i,0,x.size()+1){
			FOR(j,0,y.size()+1){
				if(i==0||j==0)dp[i][j]=0;
				else{
					if(x[i-1]==y[j-1])dp[i][j] = max({dp[i-1][j-1]+1,dp[i][j-1],dp[i-1][j]});
					else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
				} 
			}
		}
		ans.push_back(dp[x.size()][y.size()]);
	}
	FOR(i,0,ans.size()){
		cout<<ans[i]<<endl;
	}
	return 0;
}

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

int lcs(string x, string y) {
    x = ' ' + x;
    y = ' ' + y;
    int m = x.length();
    int n = y.length();
    int memo[m][n];
    rep(i, m) memo[i][0] = 0;
    rep(i, n) memo[0][i] = 0;
    for(int i = 1; i < m; i++) {
        for(int j = 1; j < n; j++) {
            if(x[i] == y[j]) {
                memo[i][j] = memo[i - 1][j - 1] + 1;
            } else {
                memo[i][j] = max(memo[i - 1][j], memo[i][j - 1]);
            }
        }
    }

    return memo[m-1][n-1];
}

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int q;
    string x, y;
    cin >> q;
    rep(i, q) {
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
}

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

#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define N 1050

int lcs(string X, string Y) {
    int c[N + 1][N + 1];
    int m    = X.size();
    int n    = Y.size();
    int maxV = 0;

    X = ' ' + X;
    Y = ' ' + Y;

    for (int i = 0; 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]);
            }
            maxV = max(maxV, c[i][j]);
        }
    }
    return maxV;
}

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout << fixed << setprecision(5);

    string s1, s2;
    int    n;
    cin >> n;

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

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll
//
//vector<int> G[20];
//
//// 巡回セールスマン問題
//
//signed main(){
//  int v,e;
//  cin>>v>>e;
//
//  for(int i=0; i<e; i++){
//    int a,b;
//    cin>>a>>b;
//    G[a].push_back(b);
//  }
//}























////  最長共通部分列

int dp[1005][1005];

signed main(){
  int n;
  cin>>n;
  for(int i=0; i<n; i++){
    string s1,s2;
    cin>>s1>>s2;
    s1=" "+s1;
    s2=" "+s2;
    int maxl=0;
    for(int i=0; i<=s1.size()-1; i++) for(int j=0; j<=s2.size(); j++) dp[i][j]=0;
    for(int i=1; i<=s1.size()-1; i++){
      for(int j=1; j<=s2.size(); j++){
        if(s1[i]==s2[j]) dp[i][j]=dp[i-1][j-1]+1;
        else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        maxl=max(maxl,dp[i][j]);
      }
    }
    cout<<maxl<<en;
  }
}