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 <vector>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

void lcs(string s, string t){
    int m = s.size() + 1;
    int n = t.size() + 1;
    vector<vector<int>> dp(m, vector<int>(n));
    rep(i, m) dp[i][0] = 0;
    rep(i, n) dp[0][i] = 0;
    for (int i = 1; i < m; i++){
        for (int j = 1; j < n; j++){
            if (s[i - 1] == t[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];
        }
    }
    cout << dp[m - 1][n - 1] << endl;
}

int main(){
    int q;
    cin >> q;
    string s, t;
    rep(k, q) {
        cin >> s >> t;
        lcs(s, t);
    }
    return 0;
}

C++: #include <iostream>
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() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin>>n;
  string s1,s2;
  for (int i=0; i<n; i++) {
    cin>>s1>>s2;
    cout<<lcs(s1,s2)<<endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(){
  int k,m,n,i,j,q,c[1001][1001],max=0;
  char X[1000],Y[1000];
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%s %s",X,Y);
    m=strlen(X);
    n=strlen(Y);
    for(j=m;j>=1;j--){
      X[j]=X[j-1];
    }
    X[0]=' ';
    X[m+1]='\0';
    for(j=n;j>=1;j--){
      Y[j]=Y[j-1];
    }
    Y[0]=' ';
    Y[n+1]='\0';
    for(j=1;j<=m;j++)c[j][0]=0;
    for(j=1;j<=n;j++)c[0][j]=0;
    for(j=1;j<=m;j++){
      for(k=1;k<=n;k++){
	if(X[j]==Y[k])c[j][k]=c[j-1][k-1]+1;
	else{
	  if(c[j][k-1]>c[j-1][k])c[j][k]=c[j][k-1];
	  else c[j][k]=c[j-1][k];
	}
	if(max<c[j][k])max=c[j][k];
      }
    }
    printf("%d\n",max);
    max=0;
  }
  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=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]);
      }
      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<bits/stdc++.h>
using namespace std;

int main(){
    int num;
    cin >> num;
    for(int ii=0; ii<num; ii++){
        // 文字列の受け取り
        string s, t;
        cin >> s >> t;
        int n = s.size(), m = t.size();

        // DPテーブルの準備
        int dp[n+1][m+1] = {};
        //dp[0][0] = 0;

        // DPテーブルを更新
        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;
    }
}

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

using namespace std;

int m[1000][10000];
int main(){
  int n;
  cin>>n;
  char A[1001];
  char B[1001];
  for(int i=0;i<n;i++){
    cin>>A;
    cin>>B;
    int x;
    int y;
    for(x=0;A[x]!='\0';x++){
      for(y=0;B[y]!='\0';y++){
	if(A[x]==B[y]){
	  m[x+1][y+1]=m[x][y]+1;
	}
	else {
	  if(m[x][y+1]>m[x+1][y]){
	    m[x+1][y+1]=m[x][y+1];
	  }
	  else m[x+1][y+1]=m[x+1][y];
	}
      }
    }
    cout<<m[x][y]<<endl;

  }

  
  return 0;
}

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

int LCS() {
    int i, j, maxl;
    string X, Y;
    int C[MAX+1][MAX+1];

    cin >> X >> Y;
    size_t X_len = X.length();
    size_t Y_len = Y.length();

    for (i=0; i<=X_len; i++) {
        for (j=0; j<=Y_len; j++) {
            if (i==0 || j==0) C[i][j]=0;
            else {
                if (X[i]==Y[j]) {
                    C[i][j]=C[i-1][j-1]+1;
                    maxl = max(C[i][j], maxl);
                } else C[i][j]=max(C[i-1][j], C[i][j]);
            }
        }
    }

    return maxl;
}

int main() {
    int n, i;
    
    cin >> n;
    for (i=0; i<n; i++) {
        printf("%d\n", LCS());
    }

    return 0;
}

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

int LCS(string X, string Y) {
  /*
  if (X.length() == 0 || Y.length() == 0) {
    return 0;
  }
  else if (X[X.length()-1] == Y[Y.length()-1]) {
    string miniX = X.substr(0, X.length()-1),  miniY = Y.substr(0, Y.length()-1);
    return LCS(miniX, miniY) + 1;
  }
  else {
    string miniX = X.substr(0, X.length()-1),  miniY = Y.substr(0, Y.length()-1);
    return max(LCS(miniX, Y), LCS(X, miniY));
  }
  */
 int m = X.length(), n = Y.length();
 int c[m+1][n+1];
 for (int i = 0; i <= m; i++) {c[i][0] = 0;}
 for (int i = 0; i <= n; i++) {c[0][i] = 0;}
 int maxL = 0;
 X = ' '+ X; Y = ' ' + Y;
 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]);
  maxL = max(maxL, c[i][j]);   
  }
 }
 return maxL;
}
int main(void) {
  int q; cin >> q;
  string X[q], Y[q];
  for (int i = 0; i < q; i++)  {
    cin >> X[i] >> Y[i];
  }

  int ans[q];
  for (int i = 0; i < q; i++) {
    ans[i] = LCS(X[i], Y[i]);
  }

  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
}