Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

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