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 <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <stack>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <bitset>

/*----------------------------------------------------------------*/

using ld = long double;
using vld = std::vector<ld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using str = std::string;
using vstr = std::vector<str>;
using vb = std::vector<bool>;
using vvb = std::vector<vb>;

/*----------------------------------------------------------------*/

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }
template<typename T> T sqr(T a) { return a * a; }

/*----------------------------------------------------------------*/

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

/*----------------------------------------------------------------*/

ll gcd(ll n, ll m) { return m != 0 ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; sqr(i) <= n; i++)
        if (n % i == 0) return false;
    return true;
}
ll popcnt(ll n) {
    n = ((n & 0xaaaaaaaaaaaaaaaa) >> 1) + (n & 0x5555555555555555);
    n = ((n & 0xcccccccccccccccc) >> 2) + (n & 0x3333333333333333);
    n = ((n & 0xf0f0f0f0f0f0f0f0) >> 4) + (n & 0x0f0f0f0f0f0f0f0f);
    n = ((n & 0xff00ff00ff00ff00) >> 8) + (n & 0x00ff00ff00ff00ff);
    n = ((n & 0xffff0000ffff0000) >> 16) + (n & 0x0000ffff0000ffff);
    n = ((n & 0xffffffff00000000) >> 32) + (n & 0x00000000ffffffff);
    return n;
}

/*----------------------------------------------------------------*/

void solve();

/*----------------------------------------------------------------*/

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}

void solve() {
    ll q; std::cin >> q;

    for (ll i = 0; i < q; i++) {
        str x, y; std::cin >> x >> y;
        ll x_len = x.length(), y_len = y.length();
        vvll dp(x_len + 1, vll(y_len + 1, 0));
        for (ll i = 1; i <= x_len; i++) for (ll j = 1; j <= y_len; j++)
            if (x[i - 1] == y[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
        std::cout << dp[x_len][y_len] << '\n';
    }
}

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;
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		cin >> X >> Y;
		cout << lcs(X, Y) << endl;
	}
	return 0;
}

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

int main(){
  int n;
  char x[1001],y[1001];
  int dp[1002][1002];
  


  //load n;
  cin >>n;
  for(int i=0;i<n;i++){
    //initialize
    for(int i=0;i<1002;i++){
      for(int j=0;j<1002;j++){
	dp[i][j]=0; 
      }
    }
    //load string
    scanf("%s",x);
    scanf("%s",y);
    //dp
    for(int j=0;j<strlen(x);j++){
      for(int k=0;k<strlen(y);k++){
	if(x[j]==y[k]){
	  dp[j+1][k+1]=dp[j][k]+1;
	}

	else{
 
	  if(dp[j][k+1]>dp[j+1][k]){
	    dp[j+1][k+1]=dp[j][k+1];
	  }

	  else{
	    dp[j+1][k+1]=dp[j+1][k];
	  }
	}
      }
    }

    //print
    cout <<dp[strlen(x)][strlen(y)]<<endl;
  }



  return 0;
}

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 = new int*[1001];
	for(int i = 0; i < 1001; i++){
		table[i] = new int[1001];
		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 <vector>
#include <string>
#include <algorithm>

const int Size = 1000;
int dp[Size + 1][Size + 1];
std::string x;
std::string y;

int calc(int m, int n)
{
	int ans = 0;

	if (dp[m][n] != -1) {
		return dp[m][n];
	}

	if (m == 0 || n == 0) {
		return 0;
	}

	if (x[m - 1] == y[n - 1]) {
		ans = calc(m - 1, n - 1) + 1;
		dp[m][n] = ans;
		return ans;
	}

	ans = std::max(calc(m, n - 1), calc(m - 1, n));
	dp[m][n] = ans;
	return ans;
}


int main()
{
	int q;
	std::vector<int> ans;
	std::cin >> q;

	for (int i = 0; i < q; i++) {
		std::cin >> x >> y;
		for (int j = 0; j < Size + 1; j++) {
			for (int k = 0; k < Size + 1; k++) {
				dp[j][k] = -1;
			}
		}
		int temp = calc(x.size(), y.size());
		ans.push_back(temp);
	}

	for (unsigned int i = 0; i < ans.size(); i++) {
		std::cout << ans[i] << std::endl;
	}

	return 0;
}