Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		strX := nextText(sc)
		strY := nextText(sc)
		fmt.Println(calcLcs(strX, strY))
	}
}

func calcLcs(strX, strY string) int {
	lenX, lenY := len(strX), len(strY)
	memo := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		memo[i] = make([]int, lenY+1)
	}

	lcs := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if strX[i-1] == strY[j-1] {
				memo[i][j] = memo[i-1][j-1] + 1
			} else {
				if memo[i-1][j] > memo[i][j-1] {
					memo[i][j] = memo[i-1][j]
				} else {
					memo[i][j] = memo[i][j-1]
				}
			}
			if memo[i][j] > lcs {
				lcs = memo[i][j]
			}
		}
	}
	return lcs
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: //#if 0
//????????????????§£?????????????????????????????????????????????????????????C++??§string??????????????§???
//?????????????????§???????????§???AOJ?????????????????????Runtime Error??????????????????????????????
//??£????????¨??????????????????????????????????????????????????????Runtime Error???????????¨???????????????
//??§???????????????????????????????????§???
//#endif
#include<iostream>
#include<string>
#define lth 1010

using namespace std;

int main()
{
	int n, L[1010][1010], Lmax = 0, *save;
	string *Xi, *Yi;
	cin >> n;
	save = new int[n];

		Xi = new string[lth];
		Yi = new string[lth];
	

	for (int k = 0; k < n; k++)
	{
		Lmax = 0;
		string X, Y;
		cin >> X >> Y;
		for (int i = 0; i <= X.length(); i++)
		{
			if (i != 0)
				Xi[i] = X.substr(0, i );
		}
		for (int i = 0; i <= Y.length(); i++)
		{
			if (i != 0)
				Yi[i] = Y.substr(0, i );
		}
		for (int i = 0; i <= X.length(); i++)
			for (int j = 0; j <= Y.length(); j++)
			{
				if (i == 0 || j == 0)
					L[i][j] = 0;
				else if (Xi[i][i - 1] == Yi[j][j - 1])
				{
					L[i][j] = L[i - 1][j - 1] + 1;
				}
				else
				{
					L[i][j] = (L[i][j - 1] > L[i - 1][j]?L[i][j - 1] : L[i - 1][j]);
				}
				if (Lmax < L[i][j]) Lmax = L[i][j];
			}
		save[k] = Lmax;
	}

	for (int i = 0; i < n; i++)
		cout << save[i] << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

static const int N = 10000;

int lcs(string X, string Y);

int main(void){
	string s1, s2;
	int n; cin >> n;
	int i;
	REP(i, n) {
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}
	return 0;
}

// longest common sequence
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;
	int i, j;
	FOR(i, 1, m + 1) FOR(j, 1, n + 1) {
		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;
}

C++: #include <array>
#include <vector>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

constexpr int N = 1000;

int dp[N+1][N+1];

int solve(const string& x, const string& y)
{
    int m = x.size();
    int n = y.size();

    FOR(i, 0, m+1)
        dp[i][0] = 0;
    FOR(j, 0, n+1)
        dp[0][j] = 0;

    FOR(i, 1, m+1) {
        FOR(j, 1, n+1) {
            if(x[i-1] == y[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    return dp[m][n];
}

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

    REP(_, n) {
        string x, y;
        cin >> x;
        cin >> y;

        int lcs_len = solve(x, y);
        cout << lcs_len << "\n";
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;
// Welcome to my source code!

int lcs(string x, string y) {
    int m = x.size();
    int n = y.size();
    int c[m+1][n+1] = {};
    int maxv = 0;
    x = ' ' + x;
    y = ' ' + y;
    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]);
            }
            maxv = max(maxv, c[i][j]);
        }
    }
    return maxv;
}

int main() {
    int q;
    string x, y;
    cin >> q;
    REP(i,q) {
        cin >> x >> y;
        cout << lcs(x,y) << endl;
    }
}

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

static const int N = 1000;

int lcs(string X, string Y) {
    //DP memotable: c
    int c[N+1][N+1];
    int xSize = X.size();
    int ySize = Y.size();
    int maxl = 0;
    //first char will be empty because of dp table
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 0; i <= xSize; i++) c[i][0] = 0;
    for (int j = 0; j <= ySize; j++) c[0][j] = 0;

    for (int i = 1; i <= xSize; i++) {
        for (int j = 1; j <= ySize; 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]);
        }
    }
    /*
    for (int i = 1; i <= xSize; i++) {
        for (int j = 1; j <= ySize; j++) {
            cout << c[i][j] << " ";
        }
        cout << endl;
    }
    */
    return maxl;
}

int main()
{
    int n; cin >> n;
    //string s1 = "abcbdab";
    //string s2 = "bdcaba";
    string s1, s2;
    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}

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

using namespace std;

string a,b;

int lcs(int i,int j){
  if(i==0 || j==0) return 0;
  if(a[i]==b[j]){
    return lcs(i-1,j-1)+1;
  }else{
    return max(lcs(i,j-1),lcs(i-1,j));
  }
}

int main(){
  int n; cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    a = ' ' + a;
    b = ' ' + b;
    cout<<lcs(a.size()-1,b.size()-1)<<endl;
  }
}

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 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;
}
   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;
}