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 <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>

int lcs(const std::string& x, const std::string& y)
{
    int c[x.size()][y.size()] = {0};
    for (int i = 0; i < x.size(); ++i) {
        for (int j = 0; j < y.size(); ++j) {
            if (i == 0) {
                if (j == 0) {
                    if (x[i] == y[j]) {
                        c[i][j] = 1;
                    } else {
                        c[i][j] = 0;
                    }
                } else {
                    if (x[i] == y[j]) {
                        c[i][j] = 1;
                    } else {
                        c[i][j] = c[i][j-1];
                    }
                }
            } else if (j == 0) {
                if (i == 0) {
                    if (x[i] == y[j]) {
                        c[i][j] = 1;
                    } else {
                        c[i][j] = 0;
                    }
                } else {
                    if (x[i] == y[j]) {
                        c[i][j] = 1;
                    } else {
                        c[i][j] = c[i-1][j];
                    }
                }
            } else {
                if (x[i] == y[j]) {
                    c[i][j] = c[i-1][j-1] + 1;
                } else {
                    c[i][j] = std::max(c[i][j-1], c[i-1][j]);
                }
            }
        }
    }

    return c[x.size() -1][y.size()-1];
}

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

    std::string x;
    std::string y;
    for (int i = 0; i < n; ++i) {
        std::cin >> x >> y;
        std::cout << lcs(x, y) << std::endl;
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

int lcs(string X, string Y) {
  int memo[1010][1010];
  int maxl = 0;
  int k = 0;
  for (int i = 0; i < X.size(); i++) {
    for (int j = 0; j < Y.size(); j++) {
      if (i <= 0 || j <= 0) {
        if (X[i] == Y[j]) {
          memo[i][j] = 1;
        } else {
          memo[i][j] = 0;
        }
      }
      else {
        if (X[i] == Y[j]) {
          memo[i][j] = memo[i-1][j-1] + 1;
        } else {
          memo[i][j] = max(memo[i-1][j], memo[i][j-1]);
        }
      }
      maxl = max(maxl, memo[i][j]);
      //cout << i << "," << j << "," << X[i] << "," << Y[j] << "," << maxl << endl;
    }
  }
  return maxl;
}

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

C++: #include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

//I can't understand,so I imitated yutaka watabe's book.
//I think this problem has 5 star rank difficulty.

void calc(char X[],char Y[]){
	int X_length=0,Y_length=0;
	int table[1001][1001];
	for(int i = 0; i < 1001; i++){
		for(int k = 0; k < 1001; k++)table[i][k] = 0;
	}
	for(int i = 0; X[i] != '\0'; i++)X_length++;
	for(int i = 0; Y[i] != '\0'; i++)Y_length++;
	int max_succeed = 0;
	for(int i = 0; i < X_length; i++){
		for(int k = 0; k < Y_length; k++){
			if(X[i] == Y[k]){
				table[i+1][k+1] = table[i][k] + 1;
			}else{
				table[i+1][k+1] = max(table[i+1][k],table[i][k+1]);
			}
			max_succeed = max(max_succeed,table[i+1][k+1]);
		}
	}
	printf("%d\n",max_succeed);
}

int main(){
	int q;
	char X[1001],Y[1001];
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%s %s",X,Y);
		calc(X,Y);
	}
    return 0;
}

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

int q;
string X, Y;


int main(void) {
  cin >> q;
  for (int i = 0; i < q; i++) {
    int dp[1000][1000];
    cin >> X >> Y;
    memset(dp, 0, sizeof(dp));

    dp[0][0] = X[0] == Y[0];
    for (int j = 1; j < Y.size(); j++) dp[0][j] = dp[0][j-1] || X[0] == Y[j];
    for (int j = 1; j < X.size(); j++) dp[j][0] = dp[j-1][0] || X[j] == Y[0];

    for (int j = 1; j < X.size(); j++) {
      for (int k = 1; k < Y.size(); k++) {
        if (X[j] == Y[k]) {
          dp[j][k] = dp[j-1][k-1] + 1;
        } else {
          dp[j][k] = max(dp[j-1][k], dp[j][k-1]);
        }
      }
    }

    cout << dp[X.size()-1][Y.size()-1] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
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 maxl=0;
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 0; i <= m; i++){
        c[i][0] =0;
    }
    for (int i= 0; i <= n; i++){
        c[0][i] = 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) <<endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int p[1001][1001]={0};
int main(){
int i,j,q,e,l,z,m,u,n;
char s[2001],c[2001];
cin>>q;
for(e=0;e<q;e++){
scanf("%s %s",s,c);
l=strlen(s);
z=strlen(c);

for(i=0;i<=l;i++){
	for(j=0;j<=z;j++){
		p[i][j]=0;
	}
}
for(i=1;i<=z;i++){
	for(j=1;j<=l;j++){
		if(c[i-1]==s[j-1])p[j][i]=p[j-1][i-1]+1;
		else p[j][i]=max(p[j][i-1],p[j][i-1]);
	}
}
cout<<p[l][z]<<endl;
}
return 0;
}