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 <bits/stdc++.h>
using namespace std;
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
  const char* delimiter = "";
  for(const auto& x:v) cout << exchange(delimiter, ",") << x;
  return os;
}
// ALDS1_10_C: 最長共通部分列 (LCS)
int32_t main(){
  size_t q; cin>>q;
  for(size_t p=0; p<q; ++p){
    string s,t; cin>>s>>t;
    vector<vector<size_t>> dp(s.size()+1,vector<size_t>(t.size()+1));
    // i=0
    for(auto&& x:dp[0]) x=0;
    for(size_t i=1; i<dp.size(); ++i){
      // j=0
      dp[i][0]=0;
      for(size_t j=1; j<dp[i].size(); ++j){
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        if(s[i-1]==t[j-1]) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
      }
    }
    cout<<dp.back().back()<<endl;
  }
}

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

#define MAX 1000

int c[MAX+1][MAX+1];

int lcs(string A, string B)  {
    int a = A.length();
    int b = B.length();
    int maxl = 0;

    A = ' ' + A;
    B = ' ' + B;
    //配列を作る
    for(int i=0; i<a; i++) {
        c[i][0] = 0;
    }
    for(int j=0; j<b; j++) {
        c[0][j] = 0;
    }
    for(int i=1; i<=a; i++) {
        for(int j=1; j<=b; j++) {
            if(A[i]==B[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) << endl;
    }
    return 0;
}

C++: 
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int q;
  cin>>q;

  while(q--){
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();

    vector<vi> dp(n+1,vi(m+1,0));

    loop(i,1,n+1)loop(j,1,m+1){
      if(s[i-1] == t[j-1]){
        dp[i][j] = dp[i-1][j-1] + 1;
      }else{
        dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
      }
    }

    cout << dp[n][m] << endl;
  }
}

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

#define N 1000

int lsc(string x,string y){
    int c[N+1][N+1];
    int m=x.size();
    int n=y.size();
    int maxl=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;
}

using namespace std;

int main() {
    string x,y;
    int n;
    cin>>n;
    for (int i = 0; i <n ; ++i) {
        cin>>x>>y;
        cout<<lsc(x,y)<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>

using namespace std;

static const int N = 1000;

int c[N + 1][N + 1];
int lcs(string s1, string s2){
	int m = s1.size();
	int n = s2.size();
	int maxL = 0;

	s1 = ' ' + s1;
	s2 = ' ' + s2;
	for (int i = 1; i <= m; ++i) c[i][0] = 0;
	for (int i = 1; i <= n; ++i) c[0][i] = 0;

	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (s1[i] == s2[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) << endl;
	}

	return 0;
}

C++: #include <iostream> 
#include <cstring> 
using namespace std;
int c[1001][1001];

int lcs(string x, string y)
{
    int maxl = 0;
    int m = x.length(), n = y.length();
 
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 0; j <= n; j++) c[0][j] = 0;


    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (x[i-1] == y[j-1])
            { 
                // if(i==0 || j==0) c[i][j] = 1;
                c[i][j] = c[i-1][j-1] + 1; 
            }else
            {
                // if(i==0 || j==0) c[i][j] = 0;
                c[i][j] = max(c[i][j-1], c[i-1][j]);
            }
            maxl = max(maxl, c[i][j]);
        } 
    } 
    // printf("%d\n", c[m][n]);
    return c[m][n];
}

int main()
{
    string x,y;
    int q;
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        int ans = lcs(x, y);
        cout<<ans<<endl;
    }
    return 0;
}

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

static const int MAX = 1000;
int dp[MAX + 1][MAX + 1];

void lcs(string s1, string s2){
    for (int i = 0; i < MAX + 1; i++){
        for (int j = 0; j < MAX + 1; j++) dp[i][j] = 0;
    }
    
    for (int i = 0; i < s1.size(); i++){
        for (int j = 0; j < s2.size(); j++){
            if (s1[i] == s2[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]);
        }
    }
    cout << dp[s1.size()][s2.size()] << endl;
}

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

    string s1, s2;
    for (int i = 0; i < n; i++){
        cin >> s1 >> s2;
        lcs(s1, s2);
    }

    return 0;
}