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>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int MAX_L = 10000;
int q;

string data[MAX_N][2];
ll mem[MAX_L][MAX_L];

ll eval(string s1, string s2, int i, int j){
	int ii = i - 1;
	int jj = j - 1;
	if (ii == -1 || jj == -1) return 0;
	if (s1[ii] == s2[jj]) return mem[i - 1][j - 1] + 1;
	if (s1[ii] != s2[jj]) return max(mem[i - 1][j], mem[i][j - 1]);
	throw "exception";
}

ll solve(string s1, string s2){

	int L1 = s1.size();
	int L2 = s2.size();
	rep(i, L1 + 1){
		rep(j, L2 + 1)
		{
			mem[i][j] = eval(s1, s2, i, j);
		}
	}

	return mem[L1][L2];
}

int main() {

	cin >> q;
	rep(i, q){
		cin >> data[i][0];
		cin >> data[i][1];
	}

	rep(i, q){
		cout << solve(data[i][0], data[i][1]) << endl;
	}
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

static const int N = 100;

int lcs(string X, string Y);

int main(void){
	string s1, s2;
	int n;
	cin >> n;
	int i;
	REP(i, n) {
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}
	return 0;
}

// longest common sequence
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;
	int i, j;
	FOR(i, 1, m + 1) FOR(j, 1, n + 1) {
		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;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MAX 1001

static int dp[MAX][MAX];

int main() {
	int q; cin >> q;
	while (q--) {
		memset(dp, 0, sizeof(dp));
		string X, Y; cin >> X >> Y;
		for (int i = 1; i <= X.size(); i++) {
			for (int j = 1; j <= Y.size(); j++) {
				if (X[i - 1] == Y[j - 1]) {
					//cout << i << j << X[i - 1] << endl;
					dp[i][j] = dp[i - 1][j - 1] + 1;
				}
				else {
					dp[i][j] = max(
						dp[i - 1][j],
						dp[i][j - 1]
					);
				}
			}
		}
		//for (int i = 0; i <= Y.size(); i++) {
		//	for (int j = 0; j <= X.size(); j++) {
		//		cout << dp[j][i] << " ";
		//	}
		//	cout << endl;
		//}
		cout << dp[X.size()][Y.size()] << endl;

	}

	return 0;
}

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

int lcs(string &X, string &Y)
{
	static int Z[1001][1001];
	int m = X.size();
	int n = Y.size();
	int i, j;

	for (i = 1; i <= m; i++) {
		for (j = 1; j <= n; j++) {
			if (X[i - 1] == Y[j - 1])
				Z[i][j] = Z[i - 1][j - 1] + 1;
			else
				Z[i][j] = max(Z[i - 1][j], Z[i][j - 1]);
		}
	}
	return Z[m][n];
}

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

	string X, Y;
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> X >> Y;
		cout << lcs(X, Y) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>



using namespace std;

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

int main() {
    

    string s1,s2;
    int p;
    cin >> p;
    for (int i= 0;i<p;i++){
        cin >> s1 >> s2;
        cout << lcs(s1,s2) << endl;
    }
    return 0;


}

C++: #include<iostream>
#include<string>
int main()
{
  int n;
  int an[1000];
  int l=0;
  std::cin>>n;
  std::string x;
  std::string y;
  int ans[1000][1000];
  int j,k;
  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<1000;j++){
      for(int k=0;k<1000;k++){
	ans[j][k]=0;
      }
    }
    for(int j=0;j<x.size();j++){
      for(int k=0;k<y.size();k++){
	if(x[j]==y[k]){
	  ans[j][k]=ans[j-1][k-1]+1;
	}else{
	  if(ans[j][k-1]>ans[j-1][k]){
	    ans[j][k]=ans[j][k-1];
	  }else{
	    ans[j][k]=ans[j-1][k];
	  }
	}
      }
    }
    std::cout<<ans[x.size()-1][y.size()-1]<<'\n';  
  }
  return 0;
}