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++: #if 0
PDFに記載されている方針がわかりやすかったので、比較的簡単に解くことができた。
#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int Q;
int L[1000+10][1000+10];

int main() {
  cin >> Q;
  string X, Y;
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < 1000+10; j++) {
      L[0][j] = 0; L[j][0] = 0;
    }
    cin >> X >> Y;
    for (int x = 1; x <= X.length(); x++) {
      for (int y = 1; y <= Y.length(); y++) {
        if (X[x-1] == Y[y-1])
          L[x][y] = L[x-1][y-1] + 1;
        else
          L[x][y] = max(L[x-1][y], L[x][y-1]);
      }
    }
    cout << L[X.length()][Y.length()] << endl;
  }
}

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++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int lcs(string s, string t) { // 最長共通部分列長
  int n = s.size();
  int m = t.size();
  vector<vector<int>> dp(n+1,vector<int>(m+1));
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      if(s[i] == t[j]) {
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
      }
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
    }
  }
  return dp[n][m];
}


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

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

using namespace std;

int dp[1010][1010];

int main() {
    int q;  cin >> q;
    int *ans = new int[q];
    string s, t;
    int ls, lt, i, j;
    for (int k = 0; k < q; k++) {
        cin >> s >> t;
        ls = s.size(), lt = t.size();

        for (i = 0; i <= ls; i++) {
            for (j = 0; j <= lt; j++)
                dp[i][j] = 0;
        }

        for (i = 0; i < ls; i++) {
            for (j = 0; j <= lt; j++) {
                if (s[i] == t[j])
                    dp[i+1][j+1] = max(dp[i][j]+1, max(dp[i+1][j], dp[i][j+1]));
                else
                    dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }   
        ans[k] = dp[ls][lt];
    }
    for (int k = 0; k < q; k++)
        cout << ans[k] << endl;
    return 0;
}

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

using namespace std;

#define 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=0; i<=m; ++i) c[i][0] = 0;
  for(int i=1; i<=n; ++i) c[0][i] = 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;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int lcs(string x, string y) {
	int c[1200][1200];
	int m = x.size();
	int 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;
	c[0][0] = 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]);
			}
		}
	}
	return c[m][n];
}

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

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;


int main()
{
	int N;
	cin >> N;
	rep(ii,N)
	{
	string s,t;
	cin >> s >> t;
	int n=s.size(),m=t.size();
	vector<vector<int>> dp(n+1,vector<int>(m+1,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			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;
	}
	return 0;
}

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

using namespace std;

int main(){
    vector< vector<int> > dp(1001,vector<int>(1001));
    int q;
    cin >> q;
    
    for(int i=0; i<q; i++){
        string x;
        string y;
        cin >> x;
        cin >> y;
        int xLength = x.length();
        int yLength = y.length();

        for(int j=0; j<xLength; j++){
            for(int k=0; k< yLength; k++){
                int suggest[3];
                if(x[j] == y[k]){
                    dp[j+1][k+1] = dp[j][k] + 1; 
                }else{
                    if(dp[j+1][k] > dp[j][k+1]){
                        dp[j+1][k+1] = dp[j+1][k]; 
                    }else{
                        dp[j+1][k+1] = dp[j][k+1];
                    }
                }
            }
        }
        cout << dp[xLength][yLength] << endl;
    }
    return 0;
}