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<algorithm>
#include<string>

using namespace std;

int lcs (string x, string y) {

    int m, n, c[1001][1001], i, j, maxl = 0;

    m = x.size();
    n = y.size();

    x = ' ' + x;
    Y = ' ' + y;

    for (i = 0; i <= m; i++) {
        c[i][0] = 0;
    }
    for (j = 1; j <= n; j++) {
        c[0][j] = 0;
    }

    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] = max (c[i - 1][j], c[i][j - 1]);
                }

                maxl = max (max, c[i][j]);

            }
    }

    return maxl;

}



int main () {

    int N, i;
    string x, y;

    cin >> N;

    for (i = 0; i < n; i++) {
        cin >> x >> y;
        cout << lcs (x, y) << endl;

    }

    return 0;

}

C++: #include "bits/stdc++.h"

using namespace std;

// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_10_C

int lcs(int currX, int currY, const string& X, const string& Y, vector<vector<int>>& memo) {
    if (currX == X.size() || currY == Y.size()) {
        return 0;
    }
    if (memo[currX][currY] >= 0) {
        return memo[currX][currY];
    }

    int ret;
    if (X[currX] == Y[currY]) {
        ret = lcs(currX + 1, currY + 1, X, Y, memo) + 1;
    }
    else {
        int moveX = lcs(currX + 1, currY, X, Y, memo);
        int moveY = lcs(currX, currY + 1, X, Y, memo);
        ret = max(moveX, moveY);
    }
    memo[currX][currY] = ret;
    return ret;
}

void Main() {
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        string X, Y;
        cin >> X;
        cin >> Y;

        vector<vector<int>> memo(1005, vector<int>(1005, -1));
        int ans = lcs(0, 0, X, Y, memo);
        cout << ans << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "DataStructure.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
typedef pair<int, int> p;
const int INF = 1000000000;
int main(){
	int n; cin >> n;
	for (int k = 0; k < n; k++) {
		char s[1000], t[1000];
		scanf("%s",&s); scanf("%s", &t);
		int i = 0, j = 0;
		int dp[101][101];
		fill(dp[0], dp[101], 0);
		int res = 0;
		while (s[i] != '\0'){
			while (t[j] != '\0') 
			{
				if (s[i] == t[j])dp[i + 1][j + 1] = dp[i][j] + 1;
				else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
				res = dp[i + 1][j + 1];
				//cout << "i " << i << "j " << j << endl;
				//cout << "dp" << dp[i + 1][j + 1] << endl;
				j++;
			}
			i++;
			j = 0;
		}

		cout << res << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    //cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int data_num; cin >> data_num;
    int ans[data_num];
    REP(rep,data_num){
        string T,S;
        cin >> T; cin >> S;
        vector<vector<int> > dp(T.size()+1, vector<int>(S.size()+1, 0));
        REP(i,T.size()){
            REP(j,S.size()){
                if(T[i] == S[j]) {dp[i+1][j+1] = dp[i][j] + 1;}
                else {dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);}
            }
        }
        ans[rep] = dp[T.size()][S.size()];
    }

    REP(i,data_num){
        cout << ans[i] << endl;
    }
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int dp[1010][1010];

int main(void) {
    int n;
    cin >> n;
    while (n--) {
        string a, b;
        cin >> a;
        cin >> b;
        for (int i = 0; i < 1010; i++) {
            for (int j = 0; j < 1010; j++) {
                dp[i][j] = 0;
            }
        }
        for (int i = 1; i <= a.size(); i++) {
            for (int j = 1; j <= b.size(); j++) {
                if (a[i-1] == b[j-1]) {
                    dp[i][j] = max(dp[i-1][j-1] + 1, max(dp[i-1][j], dp[i][j-1]));
                } else {
                    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
                }
//                cout << dp[i][j] << "  ";
            }
//            cout << endl;
        }
        cout << dp[a.size()][b.size()] << endl;
    }
    return 0;
}

C++: //By Vlgd
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int dp[1001][1001];
void solve(){
	int m=0;
	int n1=s1.size(),n2=s2.size();
	s1=' '+s1;s2=' '+s2;
	for (int i=0;i<=n1;i++) dp[i][0]=0;
	for (int i=0;i<=n2;i++) dp[0][i]=0;
	for (int i=1;i<=n1;i++)
		for (int j=1;j<=n2;j++){
			if (s1[i]==s2[j]) dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}
	printf("%d\n",dp[n1][n2]);
}
main(){
	int q;scanf("%d",&q);
	for (int i=0;i<q;i++){
		cin>>s1>>s2;
		solve();
	}
}