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 <cstdio>
#include <cstring>
#include <algorithm>

#define SIZE 1010
class TLcsSolver
{
    int FTable[SIZE][SIZE];
    const char* FArray1;
    const char* FArray2;
    const int Fn1;
    const int Fn2;

    int Count(int i, int j)
    {
        if(i == 0 || j == 0) return 0;
        if(FArray1[i-1] == FArray2[j-1]){
            return FTable[i-1][j-1] + 1;
        }
        return std::max(FTable[i-1][j], FTable[i][j-1]);
    }
    void Solve()
    {
        for(std::size_t i = 1; i < Fn1; ++i){
            for(std::size_t j = 1; j < Fn2; ++j){
                FTable[i][j] = Count(i, j);
            }
        }
    }
    void Print()const
    {
        for(std::size_t i = 0; i < Fn1; ++i){
            for(std::size_t j = 0; j < Fn2; ++j){
                printf("%d\t", FTable[i][j]);
            }
            printf("\n");
        }
    } 
public:
    TLcsSolver(const char* a, const char* b)
     : FArray1(a), FArray2(b)
     , Fn1(std::strlen(a)), Fn2(std::strlen(b))
    {
        Solve();
        // Print();
    }
    int Answer()const
    {
        return FTable[Fn1-1][Fn2-1];
    }
};

int main()
{
    int n;
    std::scanf("%d\n", &n);
    char a[SIZE];
    char b[SIZE];
    for(int i = 0; i < n; ++i){
        std::fgets(a, SIZE, stdin);
        std::fgets(b, SIZE, stdin);
        std::printf("%d\n", TLcsSolver(a, b).Answer());
    }
    return 0;
}

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

using namespace std;

int lcs (string x, string y) {

    int m, n, c[1001][1001], i, j, maxl = 0;

    m = x.size();
    n = y.size();

    x = ' ' + x;
    y= ' ' + y;

    for (i = 0; i <= m; i++) {
        c[i][0] = 0;
    }
    for (j = 1; j <= n; j++) {
        c[0][j] = 0;
    }

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

                maxl = max (maxl, c[i][j]);

            }
    }

    return maxl;

}



int main () {

    int N, i;
    string x, y;

    cin >> N;

    for (i = 0; i < N; i++) {
        cin >> x >> y;
        cout << lcs (x, y) << endl;

    }

    return 0;

}

C++: #include <iostream>
#include <cstdio>
#include <string>
#define MAX 1001

using namespace std;


string a,b;
int lcs_memo[1001][1001];

int lcs(int i,int j){
  if(i==0 || j==0) return 0;
  if(lcs_memo[i][j]!=-1) return lcs_memo[i][j];
  if(a[i]==b[j]){
    lcs_memo[i][j] = lcs(i-1,j-1)+1;
  }else{
    lcs_memo[i][j] = max(lcs(i,j-1),lcs(i-1,j));
  }
  return lcs_memo[i][j];
}

void clear(){
  for(int i=0;i<1001;i++){
  for(int j=0;j<1001;j++){
    lcs_memo[i][j] = -1;
  }}
}

int main(){
  int n; cin>>n;
  
  for(int i=0;i<n;i++){
    clear();
    cin>>a>>b;
    a = ' ' + a;
    b = ' ' + b;
    cout<<lcs(a.size()-1,b.size()-1)<<endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define SENTINEL (-1)
#define M (1001)

// ia, ib以降のindexに対するLCSを返す
// (ia, ib)に対するLCSがわかっているとき, (ia-1, ib), (ia, ib-1)
// に対するLCSは, a[ia-1] == a[ib],...であれば+1される....
// と考えたくなるが, iaとibでカウントされている場合, ダブルカウントになってしまうから,
// 必ずしもそうとは言えない.
// X: abcbdab
// Y: bdcaba
// 1-originで考えると,
// LCS(7,6,X,Y) = 0
// LCS(6,6,X,Y) = 1
// LCS(5,5,X,Y) = 1
// LCS(4,5,X,Y) = 2
// ... ????
// 部分問題に分解したい
// X: abc
// Y: ac
// -> 2
// X[3],Y[2] -> 1
// X[2],Y[2] -> 
// lcs(i,j)
// : if a[i] == b[j] => lcs(i,j) = lcs(i-1,j-1) + 1
// : else lcs(i,j) = max ( lcs(i-1,j), lcs(i, j-1) )
// lcs(0,0) := 0
// lcs(

int lcs(int i, int j, string &a, string &b, int memo[][M]) {
	if (i==0 || j==0) {
		memo[i][j] = 0;
		return 0;
	}
	if (memo[i][j] != SENTINEL) {
		return memo[i][j];
	}
	// i, j as 1-origin index
	if (a[i-1] == b[j-1]) {
		memo[i][j] = lcs(i-1, j-1, a, b, memo) + 1;
	} else {
		memo[i][j] = max(lcs(i-1,j,a,b,memo), lcs(i,j-1,a,b,memo));
	}
	return memo[i][j];
}

// この多次元配列の書き方は汎用性がなくて嫌
void fill(int a[][M], int size1, int size2, int v) {
	for (int i=0;i<size1;++i) {
		for (int j=0;j<size2;++j) {
			a[i][j] = v;
		}
	}
}

int main () {
	int q;
	cin >> q;
	int LCS[1001][M];
	fill(LCS, 1001, 1001, SENTINEL);// -1 is sentinel
	vector<int> res;
	for (int i=0; i<q; ++i) {
		string a, b;
		cin >> a >> b;
		res.push_back(lcs(a.size(),b.size(),a,b,LCS));
		fill(LCS, M, M, SENTINEL);
	}
	for (auto i : res) {
		cout << i << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N=1000;

int lcs(string X,string Z)
{
  int c[N+1][N+1];
  int m=X.size();
  int n=Z.size();
  int maxl=0;
  X=' '+X;
  Y=' '+Z;
  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 i=1;j<=n;j++)
	{
	  if(X[i]==Z[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()
{
  stirng s1,s2;
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
    {
      cin>>s1>>s2;
      cout<<lcs(s1,s2)<<endl;
    }
  return 0;
}