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 <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


static const int N = 1000;
int c[N + 1][N + 1];

int lcs(string X, string Y)
{
	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()
{
	string s1, s2;
	int n;
	
	cin >> n;
	REP(n)
	{
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}
	
	return 0;
}


void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

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

int dp[1010][1010];

int main() {
	int q;
	cin >> q;
	vector<string> x(q), y(q);
	for (int i = 0;i < q;i++) {
		cin >> x[i] >> y[i];
	}

	for (int i = 0;i <= 1000;i++) {
		dp[i][0] = 0;
		dp[0][i] = 0;
	}
	for (int i = 0;i < q;i++) {
		for (int j = 1;j <= x[i].size();j++) {
			for (int k = 1;k <= y[i].size();k++) {
				dp[j][k] = max(dp[j - 1][k], dp[j][k - 1]);
				if (x[i][j] == y[i][k]) {
					dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + 1);
				}
			}
		}
		cout << dp[x[i].size()][y[i].size()] << endl;
	}

	return 0;
}

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

using namespace std;
static const int N = 100;

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;
	c[0][0] = 0;
	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() {
	string s1, s2;
	int n; 
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s1 >> s2;
		cout << lcs(s1, s2);
		cout << endl;
	}
	return 0;
}

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

using namespace std;
int main(){
  int dataset, i, j, k, alen, blen;
  string a, b;
  cin >> dataset;
  for (i = 0; i < dataset; ++i){
    cin >> a >> b;
    alen = a.length();
    blen = b.length();
    int lcs[alen+1][blen+1];
    for (j = 0; j <= alen; ++j){
      for (k = 0; k <= blen; ++k){
        lcs[j][k] = 0;
      }
    }
    for (j = 1; j <= alen; ++j){
      for (k = 1; k <= blen; ++k){
        if(a.at(j-1) == b.at(k-1)){
          lcs[j][k] = lcs[j-1][k-1] + 1;
        }else{
          lcs[j][k] = max(lcs[j-1][k], lcs[j][k-1]);
        }
      }
    }
    cout << lcs[alen][blen] << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int q;
  cin>>q;
  string a,b;
  int x[1001][1001];
  x[0][0]=0;
  for(int i=1;i<=1000;i++){
    x[0][i]=0;
    x[i][0]=0;
  }
  for(int i=0;i<q;i++){
    cin>>a>>b;
    for(int j=1;j<=b.size();j++){
      for(int l=1;l<=a.size();l++){
	if(a[l-1]==b[j-1]){
	  if(x[j-1][l-1]+1>x[j][l-1]){
	    x[j][l]=x[j-1][l-1]+1;
	  }else{
	    x[j][l]=x[j][l-1];
	  }
	}else{
	  if(x[j-1][l]>x[j][l-1]){
	    x[j][l]=x[j-1][l];
	  }else{
	    x[j][l]=x[j][l-1];
	  }
	}
      }
    }
    cout<<x[b.size()][a.size()]<<endl;
  }
  return(0);
}

C++: #include<cstdio>
#include<cstring>
#define N 1000

int LCS[N+1][N+1];

int LCSLength(char X[], int m, char Y[], int n){
	for(int i=0;i<=m;i++)
		LCS[i][n] = 0;
	for(int j=0;j<=n;j++)
		LCS[m][j] = 0;
	for(int i=m-1;i>=0;i--){
		for(int j=n-1;j>=0;j--){
			LCS[i][j] = LCS[i+1][j+1];
			if(X[i] == Y[j])
				LCS[i][j]++;
			if(LCS[i][j+1] > LCS[i][j])
				LCS[i][j] = LCS[i][j+1];
			if(LCS[i+1][j] > LCS[i][j])
				LCS[i][j] = LCS[i+1][j];
		}
	}
	return LCS[0][0];
}

int main(){
	char X[N+1],Y[N+1];
	int num;
	scanf("%d",&num);
	for(int i=1;i<=num;i++){
		scanf("%s %s",X,Y);
		int m = strlen(X);
		int n = strlen(Y);
		printf("%d\n",LCSLength(X,m,Y,n));
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;
    rep(k, n)
    {
        string s, t;
        cin >> s >> t;
        int s_s = s.size(), t_s = t.size();
        int dp[s_s + 1][t_s + 1];
        rep(i, s_s + 1) dp[i][0] = 0;
        rep(j, t_s + 1) dp[0][j] = 0;

        rep(i, s_s)
        {
            rep(j, t_s)
            {
                if (s[i] == t[j])
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                else
                    dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
        OP(dp[s_s][t_s]);
    }
    return 0;
}