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 null = -1;
int n;
int ans;
string x,y;
int dp[1001][1001];

int dfs(int i, int j){
    if(dp[i][j] != null){
        return dp[i][j];
    }
    int res;
    if(i == 0 || j == 0){
        return 0;
    }
    
    if(x[i-1] == y[j-1]){
        res = max(dfs(i,j-1),max(dfs(i-1,j-1)+1,dfs(i-1,j)));
    }
    else{
        res = max(dfs(i,j-1),dfs(i-1,j));
    }
    dp[i][j] = res;
    return res;
}

int main(){
    for(int i=0;i<1001;i++){
        for(int j=0;j<1001;j++){
            dp[i][j] = null;
        }
    }

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x;
        cin >> y;
        int lenx = (int)x.length();
        int leny = (int)y.length();
        //cout << lenx << " " << leny << endl;
        ans = dfs(lenx,leny);
        cout << ans << endl;
        for(int j=0;j<1001;j++){
            for(int k=0;k<1001;k++){
                dp[j][k] = null;
            }
        }
    }
    return 0;

}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int q;
  cin >> q;
  rep(i, q){
    string a, b;
    cin >> a >> b;
    vector<vector<int>> dp(b.size()+1, vector<int>(a.size()+1));
    rep(i, b.size()+1){
      rep(j, a.size()+1){
        if(i == 0 || j == 0){
          dp.at(i).at(j) = 0;
          continue;
        }
        if(a.at(j-1) == b.at(i-1)) dp.at(i).at(j) = dp.at(i-1).at(j-1) + 1;
        else dp.at(i).at(j) = max(dp.at(i-1).at(j), dp.at(i).at(j-1));
      }
    }
    cout << dp.at(b.size()).at(a.size()) << endl;
  }
  return 0;
}

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

int main()
{
	int n;
	string a, b;

	while (n--)
	{
		int memo1[1005] = {};
		int memo2[1005] = {};
		cin >> a >> b;

		for (int i = 1; i <= a.size(); i++)
		{
			memo2[0] = 0;
			for (int j = 1; j <= b.size(); j++)
			{
				if (a[i] == b[j])
					memo2[j] = max({ memo2[j - 1], memo1[j], memo1[j - 1] + 1 });
				else
					memo2[j] = max(memo2[j - 1], memo1[j]);
			}
			swap(memo1, memo2);
		}

		cout << memo1[b.size()] << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>

using namespace std;


int main(){
  int n;
  cin >> n;

  for(int i = 0; i < n; i++){
    char x[1000], y[1000];
    cin >> x >> y;
    int c[strlen(x) + 2][strlen(y) + 2];
    for(int j = 0; j <= strlen(x);j++) c[j][0] = 0;
    for(int j = 0; j <= strlen(y);j++) c[0][j] = 0;


    for(int j = 1; j <= strlen(x); j++){
      for(int k = 1; k <= strlen(y); k++){
        if(x[j - 1] == y[k - 1]) c[j][k] = c[j - 1][k - 1] + 1;
        else c[j][k] = max(c[j][k - 1], c[j - 1][k]);
      }
    }
    cout << c[strlen(x)][strlen(y)] << endl;

  }

  return 0;
}

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

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 ans=0;
  X= ' '+X;
  Y= ' '+Y;
  for(int i;i<=m;i++)c[i][0]=0;
  for(int j;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]);
      }
      ans=max(ans,c[i][j]);
    }
  
  }
  return ans;
}

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;
typedef long long ll;
#define mod 1000000007
#define MAX 1005

int table[MAX][MAX];

int LCS(string s, string t);

int main(){
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        string s,t; cin >> s >> t;
        cout << LCS(s, t) << endl;
    }
    return 0;
}

int LCS(string s, string t){
    int slen = s.length(), tlen = t.length();

    for(int i = 0; i <= slen; i++) table[0][i] = 0;
    for(int i = 0; i <= tlen; i++) table[i][0] = 0;
    for(int i = 0; i < slen; i++){
        for(int j = 0; j < tlen; j++){
            if(s[i] == t[j]){
                table[i+1][j+1] = table[i][j] +1;
            }else{
                table[i+1][j+1] = max(table[i][j+1], table[i+1][j]);
            }
        }
    }
    return table[slen][tlen];

}

C++: // Longest Common Subsequence

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
#define MAX 1001
int lcs[MAX][MAX] = {};
string x,y;

void make_lcs() {
	for (unsigned int i=0;i<=x.length();i++) {
	for (unsigned int j=0;j<=y.length();j++) {
	if (i!=0 && j!=0) {
	if (x[i] == y[j]) {
	lcs[i][j] = lcs[i-1][j-1] + 1;
	}
	else {
	lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
	}
	}
	}
	}
}

int main() {
	int n;
	cin >> n;
	for (int k=0;k<n;k++) {
	cin >> x >> y;
	make_lcs();
	cout << lcs[x.length()][y.length()] << endl;
	}
	return 0;
}