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 <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int lcs(string X, string Y) {
	int n, m;
	int c[1001][1001] = { 0 };
	int maxlcs = 0;;

	m = X.size();
	n = Y.size();


	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][j - 1],c[i - 1][j]);

			maxlcs = max(maxlcs, c[i][j]);
		}
	}
	return maxlcs;
}

int main() {

	int n;
	string S1, S2;

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

	return 0;
}

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

string X, Y;
int v[1001][1001];

int  dp(string X, string Y) {
	int n = X.size();
	int m = Y.size();

	for (int i = 0; i < n; i++) {
		v[i][0] = 0;											///０のテーブル
		for (int j = 0; j < m; j++) {
			v[0][j] = 0;
		}
	}

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

int main(void)
{
	int x;
	cin >> x;

	for (int i = 0; i < x; i++) {
		cin >> X >> Y;
		int ans = dp(X, Y);
		cout << ans << endl;
	}
}

C++: #include<bits/stdc++.h>
#define dump(a) cout << #a << " " << a << endl
#define MAX_SIZE 1000
using namespace std;

string X,Y;
int dp[MAX_SIZE+1][MAX_SIZE+1];

int dfs(int xi, int yi) {
	if (dp[xi][yi] != -1) { return dp[xi][yi]; }

	if (xi==X.size() || yi==Y.size()) { return 0; }
	else if (X[xi] == Y[yi]) {
		dp[xi][yi] = dfs(xi+1,yi+1) + 1;
	}
	else {
		dp[xi][yi] = max(dfs(xi,yi+1),dfs(xi+1,yi));
	}
	return dp[xi][yi];
}

int main() {
	int N;

	cin >> N;

	for(int i=0; i<N; i++) {
		cin >> X >> Y;
		memset(dp,-1,sizeof(dp)); //-1??§?????????
		cout << dfs(0,0) << endl;
	}

	return EXIT_SUCCESS;
}

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 max1 = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for ( int i = 0; i <= m; i++ ) c[i][0] = 0;
    for ( int j = 0; 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]);
            }
            max1 = max(max1, c[i][j]);
        }
    }

    return max1;
}

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

C++: #include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
using namespace std;

const double pi = acos(-1);
#define nyan cout<<"(=^•ω•^=)"<<endl;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)

int Q;
int dp[1100][1100];
// 1-leadingとして，
// dp[i][j] := sのi番目までの文字列とtのj番目までの文字列のLCSのサイズ

signed main(){
    cin>>Q;
    rep(q,Q){
        string s,t;
        cin>>s>>t;
        for(int i=0;i<=s.length();i++)dp[i][0]=0;
        for(int i=0;i<=t.length();i++)dp[0][i]=0;
        for(int i=1;i<=s.length();i++){
            for(int j=1;j<=t.length();j++){
                if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
                else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        cout<<dp[s.length()][t.length()]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
static const long N = 1000;
 
long lcs(string X, string Y){
    long c[N + 1][N + 1];
    long m = X.size();
    long n = Y.size();
    long maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for (long i = 1; i <= m; i++) c[i][0] = 0;
    for (long j = 1; j <= n; j++) c[0][j] = 0;
 
    for (long i = 1; i <= m; i++){
        for (long 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 = c[i][j];
        }
    }
 
    return maxl;
}
 
int main(){
    string s1, s2;
    long n;
    cin >> n;
    for (long i = 0; i < n; i++){
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}

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

int h[1001][1001];
string A;
string B;

void f(int i, int j) {
    if (A.at(i) == B.at(j)) {
            h[i][j] = h[i-1][j-1] + 1;
    } else {
        h[i][j] = max(h[i][j-1], h[i-1][j]);
    }
}

int lcs(string A, string B) {
    for (int i = 1; i <= A.length()-1; ++i) {
        for (int j = 1; j <= B.length()-1; ++j) {
            f(i, j);
        }

    }
    return h[A.length()-1][B.length()-1];
}

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

    for (int i = 0; i < n; ++i) {
        cin >> A;
        cin >> B;
        A = " " + A;
        B = " " + B;
        int a = lcs(A, B);
        cout << a << endl;
    }

    return 0;
}