Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func f() {
	var S, T string
	fmt.Scan(&S)
	fmt.Scan(&T)
	lenS, lenT := len(S), len(T)
	dp := make([][]int, lenS+1)
	for i:=0; i<lenS+1; i++ {
		dp[i] = make([]int, lenT+1)
	}
	for i:=1; i<lenS+1; i++ {
		for j:=1; j<lenT+1; j++ {
			if S[i-1] == T[j-1] {
				dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
		}
	}
	fmt.Println(dp[lenS][lenT])
}

func main(){
	var n int 
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		f()
	}
}

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