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<string>
using namespace std;

int main(){
  int i,j,n,c[1001][1001];
  string x,y;
  cin >> n;
  while(n>0){
    n--;
    cin >> x;
    cin >> y;

    int lenx = x.size();
    int leny = y.size();

    for(i = 1; i <= lenx; i++){
      c[i][0] = 0;
    }
    for(j = 1; j <= leny; j++){
      c[0][j] = 0;
    }
  
    for(i = 1; i <= lenx; i++){
      for(j = 1; j <= leny; j++){
	if(x[i-1]==y[j-1]){
	  c[i][j] = c[i-1][j-1] + 1;
	}else if(c[i-1][j] >= c[i][j-1]){
	  c[i][j] = c[i-1][j];
	}else{
	  c[i][j] = c[i][j-1];
	}
      }
    }
    cout << c[lenx][leny] << endl;
  }
  return 0;
}

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



int solve(string x, string y) {
  int xl = x.size();
  int yl = y.size();
  int lcs[MAX + 1][MAX + 1];

  int i, j;
  for (i = 0; i < xl; i++)
    lcs[i][0] = 0;
  for (j = 0; j < yl; j++)
    lcs[0][j] = 0;

  // shift
  x = " " + x;
  y = " " + y;

  int maxlcs = 0;
  for (i = 1; i <= xl; i++) {
    for (j = 1; j <= yl; j++) {
      if (x[i] == y[j]) {
        lcs[i][j] = lcs[i - 1][j - 1] + 1;
      } else {
        int a = lcs[i][j - 1];
        int b = lcs[i - 1][j];
        lcs[i][j] = max(a, b);
      }
      maxlcs = max(maxlcs, lcs[i][j]);
    }
  }
  return maxlcs;
}

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

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

// LCSセット
const int S_LEN_MAX = 1500;
ll dp[S_LEN_MAX][S_LEN_MAX];
ll LCS(string s, string t){
    // reset
    FOR(i, 0, S_LEN_MAX){
        FOR(j, 0, S_LEN_MAX){
            dp[i][j] = 0;
        }
    }

    ll n = s.size();
    ll m = t.size();
    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]);
            }
        }
    }
    return dp[n][m];
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll Q;
    cin >> Q;

    while(Q--){
        string s, t; cin >> s >> t;
        ll a = LCS(s, t);
        p(a);
    }
    
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

const int maxn = 1000 + 5;
int dp[maxn][maxn];
char x[maxn];
char y[maxn];

int main()
{
    int q;
    scanf("%d", &q);
    while (q--)
    {
        scanf("%s %s", x + 1, y + 1);
        memset(dp, 0, sizeof(dp));
        int m = strlen(x + 1);
        int n = strlen(y + 1);
        for (int i = 1; i <= m; i++)
            for (int j = 1; j <= n; j++)
            {
                if (x[i] == y[j])
                    dp[i][j] = dp[i-1][j-1] + 1;
                else
                    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        printf("%d\n", dp[m][n]);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define For(I,A,B) for(int I=(A); I < (B); ++I)
int c[1005][1005];
int main()
{
int t;
string p;
cin>>t;
getline(cin,p);
while(t--){

int x,y,z,k=0,l,i,j;
string a,b,q,r;

 For(i,0,1005)
 For(j,0,1005)
 c[i][j]=0;

 getline(cin,a);
 getline(cin,b);
 x=a.length();
 y=b.length();
 j=1;
  For(i,0,x) q[j++]=a[i];
  j=1;
  For(i,0,y) r[j++]=b[i];
 For(i,1,x+1)
 For(j,1,y+1)
 {
     if(q[i]==r[j]) c[i][j]=c[i-1][j-1]+1;
     else  c[i][j]=max(c[i-1][j],c[i][j-1]);
 }
    cout<<c[x][y]<<endl;

}

    return 0;
}

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

int dp[150+1][150+1];

int lcsSub(std::string X, std::string Y, int i, int j){
	if (i==-1 || j==-1){
		return 0;
	}
	else{
		if(X[i]==Y[j]){
			if (dp[i][j] < 0){
				dp[i][j] = lcsSub(X, Y, i-1, j-1);
			}
			return dp[i][j]+1;
		}
		else{
			int up, left;
			if (dp[i+1][j] < 0){
				dp[i+1][j] = lcsSub(X, Y, i, j-1);
			}
			left = dp[i+1][j];
			if (dp[i][j+1] < 0){
				dp[i][j+1] = lcsSub(X, Y, i-1, j);
			}
			up = dp[i][j+1];
			
			return std::max(up, left);
		}
	}
}

int lcs(std::string X, std::string Y){
	int m,n,i,j;
	m = X.length();
	n = Y.length();
	for(i=0;i<m+1;i++){
		for(j=0;j<n+1;j++){
			dp[i][j] = -1;
		}
	}
	return lcsSub(X, Y, m-1, n-1);
}
int main(void){
	int i,q,n,m;
	std::string str1, str2;
	std::cin >> q;
	for (i=0;i<q;i++){
		std::cin >> str1;
		std::cin >> str2;
		std::cout << lcs(str1, str2) << std::endl;
	}
	return 0;
}

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

int main() {
	int setN;
	cin >> setN;
	string A,B;

	for (int i=0;i<setN;i++) {
		cin >> A;
		cin >> B;
		int L[2000][2000] ={};

		for(int j=1;j<A.length()+1;j++) {
			for(int l=1;l<B.length()+1;l++) {
				if(A[j-1] == B[l-1]) {
					L[j][l] = 1+L[j-1][l-1];

				} else {
					L[j][l] = max(L[j-1][l],L[j][l-1]);
				}
				
			}
		}
		/*
		for(int j=0;j<A.length()+1;j++) {
			cout << endl;
			for(int l=0;l<B.length()+1;l++) {
				cout << L[j][l] << " ";
				
			}
		}
		*/

		cout << L[A.length()][B.length()] << endl;


	}
}