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>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define clr(a,v) memset((a),(v),sizeof(a))

int q;
int dp[1000][1000];
std::string s, t;

int rec( int i, int j )
{
  int &ret = dp[i][j];

  if( ~ret )
    return ret;

  if( i == s.size() || j == t.size() )
    return 0;

  ret = 0;

  if( s[i] == t[j] )
    ret = std::max( ret, rec( i+1, j+1 )+1 );

  ret = std::max( ret, std::max( rec( i+1, j ), rec( i, j+1 ) ) );

  return ret;
}

int main()
{
  scanf( "%d", &q );
  while( q-- )
  {
    std::cin >> s >> t;

    clr( dp, -1 );

    std::cout << rec( 0, 0 ) << std::endl;
  }

  return 0;
}

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



auto lcs(const std::string& a, const std::string& b, std::vector<std::vector<int> >*tp) {
	auto tab = *tp;

	for (auto&e : tab) {
		std::fill(std::begin(e),std::end(e),0);
	}

	for (decltype(a.size()) ai{1}; ai <= a.size();++ai) {
		for (decltype(ai) bi{1}; bi<=b.size(); ++bi) {
			if (a[ai-1] == b[bi-1])
				tab[ai][bi] = tab[ai - 1][bi - 1] + 1;
			else
				tab[ai][bi] = std::max(tab[ai - 1][bi], tab[ai][bi - 1]);
		}
	}
	return tab[a.size()][b.size()];
}

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

	std::vector<std::vector<int>> buf{};
	buf.resize(1005);
	for (auto&e : buf)
		e.resize(1005);

	for (int i{}; i < q; ++i) {
		std::string x, y;
		std::cin >> x >> y;
		std::cout << lcs(x, y, &buf)<<"\n";
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define FOR(index, init, max) for (int index = (init); index < (max); i++)
#define REP(index, max) for (int index = 0; index < (max); i++)
#define FOREACH(x, array) for (auto&& (x) : array)
#define VECCIN(vec) for (auto&& vec_i : vec) cin >> vec_i
#define VECCOUT(vec) for (const auto& vec_i : vec) cout << vec_i << endl

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

    int dp[1001][1001] = {0};

    while(q > 0) {
        string x, y;
        cin >> x >> y;

        for (int x_i = 0; x_i < x.length(); x_i++) {
            for (int y_i = 0; y_i < y.length(); y_i++) {
                if (x[x_i] == y[y_i]) {
                    dp[x_i + 1][y_i + 1] = dp[x_i][y_i] + 1;
                }
                else {
                    dp[x_i + 1][y_i + 1] = max(dp[x_i][y_i + 1], dp[x_i + 1][y_i]);
                }
            }
        }

        cout << dp[x.length()][y.length()] << endl;
        q--;
    }

    return 0;
}

C++: 
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#define MAX 1001

using namespace std;

int LCS(char *X, char *Y)
{
    int m = strlen(X);
    int n = strlen(Y);
    int  c[MAX][MAX] = {0};
    for (int i = 0; i <= m; i++)
    {
        c[0][i] = 0;
    }
    for (int j = 0; j <= n; j++)
    {
        c[j][0] = 0;
    }

    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (X[i - 1] == Y[j - 1])
            {
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else
            {
                if (c[i - 1][j] > c[i][j - 1])
                {
                    c[i][j] = c[i - 1][j];
                }
                else
                {
                    c[i][j] = c[i][j - 1];
                }
            }
        }
    }

    return c[m][n];
}

int main(int argc, char *argv[])
{
    char X[MAX], Y[MAX];
    int q;
    scanf("%d", &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%s", X);
        scanf("%s", Y);
        printf("%d\n", LCS(X, Y));
    }
    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]==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 x,y;
    int q;
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        int ans = lcs(x, y);
        cout<<ans<<endl;
    }
    return 0;
}